Skip to main content
PreparationZone Logo
PrepZone

When Reactive Wins (and When It Does Not)

WebFlux vs MVC, Project Reactor basics and the virtual-threads alternative.

Pass checkpoint below

Why this matters

  • Choosing WebFlux for a CRUD BookStore API adds Project Reactor complexity without benefit if every endpoint blocks on JPA anyway.
  • WebFlux shines when you proxy slow upstream APIs, stream large result sets, or compose many I/O calls without blocking threads.
  • Virtual threads on Java 21+ give most MVC apps reactive-scale concurrency without rewriting controllers to return Mono and Flux.

Blocking vs reactive

L1 · Fresher

MVC uses threads per request; WebFlux uses event loops and Mono/Flux return types.

Netty on WebFlux

L2 · Intermediate

WebFlux runs on Reactor Netty by default — do not block on JDBC inside reactive chains.

When to pick WebFlux

L3 · Advanced

High concurrency I/O to many slow clients or streaming SSE — not default CRUD BookStore APIs.

Hybrid pitfalls

L4 · Expert

Calling .block() in WebFlux or mixing MVC and WebFlux in one app without clear boundaries causes thread starvation.

Platform threads (carriers)
VT-1Blocked on I/O
VT-2Running
VT-3Blocked on I/O

Blocked virtual threads release their carrier — other virtual threads continue

Thousands of virtual threads multiplex onto a small pool of platform (carrier) threads.

MVC vs WebFlux decision factors

  • Thread model — MVC: one platform (or virtual) thread per request. WebFlux: event loop with non-blocking I/O.
  • Return types — MVC: plain objects, ResponseEntity. WebFlux: Mono<T>, Flux<T>.
  • Database access — JPA is blocking; WebFlux needs R2DBC or offloads blocking calls to a separate pool.
  • Ecosystem fit — MVC has mature Spring Data JPA, security, and validation. WebFlux requires reactive drivers throughout.
  • Backpressure — WebFlux supports flow control for streaming; MVC buffers the full response.

Typical MVC controller (blocking, simple)

Java
// learn:fragment
@RestController
@RequestMapping("/api/books")
public class BookController {

    private final BookService bookService;

    public BookController(BookService bookService) {
        this.bookService = bookService;
    }

    @GetMapping("/{isbn}")
    public BookDetail getBook(@PathVariable String isbn) {
        return bookService.getByIsbn(isbn);
    }

    @GetMapping
    public List<BookSummary> search(@RequestParam String query) {
        return bookService.search(query);
    }
}

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 2 sections

  • WebFlux controller (non-blocking)
  • Composing non-blocking upstream calls

Test yourself

Answer these before moving on — recall is what makes it stick.