Spring Boot supports reactive programming through the Spring WebFlux module, which enables building fully non-blocking, asynchronous applications on top of the Reactive Streams specification.
Key Points: • WebFlux can run on Netty (the default) or other non-blocking servers, instead of the traditional Servlet-based Tomcat model. • Mono represents a stream of 0 or 1 elements; Flux represents a stream of 0 to many elements, both supporting rich functional operators. • Non-blocking I/O lets a small thread pool handle a large number of concurrent connections efficiently, unlike the thread-per-request model of traditional Spring MVC. • Reactive repositories (e.g. Spring Data R2DBC or Reactive MongoDB) extend the non-blocking model all the way down to the database. • It's best suited to high-concurrency, I/O-bound workloads like streaming APIs or systems with many simultaneous slow external calls; CPU-bound work doesn't benefit as much.
Example: A real-time notification service that pushes updates to thousands of connected clients scales far better on WebFlux, since each connection doesn't tie up a dedicated thread the way it would under classic Spring MVC.
Code Example:
@GetMapping("/events")
public Flux<Notification> streamEvents() {
return notificationService.getNotificationStream();
}Interview Tip: A concise interview answer is:
"Spring Boot's reactive support comes from WebFlux, built on Reactive Streams, using Mono and Flux to represent single or multiple asynchronous values. It shines for high-concurrency, I/O-bound workloads like streaming or fan-out to many clients, since non-blocking I/O lets a small thread pool handle far more simultaneous connections than the traditional thread-per-request model."