What is Reactive Programming?
Reactive Programming is an asynchronous, non-blocking programming paradigm where:
- Data is treated as a stream of events.
- The system reacts to emitted data, errors, or completion signals.
- It’s designed for scalability and efficient resource usage, especially in I/O-heavy applications.
Core principles (Reactive Manifesto):
- Responsive – Respond to requests quickly.
- Resilient – Stay responsive under failure.
- Elastic – Adapt to changing load.
- Message-driven – Use asynchronous message passing.
In Java/Spring:
- Implemented via Project Reactor (
Mono
and Flux
).
- Used in Spring WebFlux.
Thread-per-request Model (Traditional)
How it works (Spring MVC style):
- Every incoming HTTP request is assigned its own thread from a pool.
- The thread blocks while waiting for I/O (e.g., database query, API call).
- Thread pool size limits scalability — if all threads are blocked, requests wait.
Problems: