Video in progress
When is moving from Spring MVC to WebFlux worth it, and when not?
WebFlux pays off when you have many long-lived connections (streaming, SSE, a gateway, lots of parallel external calls) and the whole stack is reactive (R2DBC, reactive drivers). In an ordinary CRUD service, especially with JDBC/JPA and Java 21 virtual threads, the complexity outweighs the benefit.
📖 Answer
Where WebFlux is strong: thousands of connections with few threads (the Netty event loop), backpressure and streaming (SSE, WebSocket, returning a large response in pieces), and a gateway or aggregator that calls 10 external services in parallel for a single request.
The cost is serious:
- The whole stack has to be reactive. JPA/JDBC are blocking, and if you call them on the event loop the whole service freezes. And R2DBC doesn't give you JPA's lazy loading, caching and other conveniences.
- Stack traces are unreadable, and debugging is hard.
- There is no ThreadLocal: MDC, transactions and SecurityContext travel through the Reactor context.
- The team has to learn to think reactively; a single
.block()ruins everything.
With Java 21 virtual threads, blocking MVC code also doesn't tie up a thread while waiting. So the main argument, "lots of parallel I/O", has become much weaker.
Before deciding, ask: is the problem really the number of threads, and has it been measured? Does every dependency have a reactive driver? Does the team have the experience?
In most cases the right choice is MVC + virtual threads, with WebFlux only in a separate service like streaming or a gateway.
Sign up to mark studied questions and save your progress.