Quick revision
The short answer
I would ask for evidence before approving it. JPA is blocking, so a real WebFlux version needs R2DBC and loses lazy loading, dirty checking and much of the mapping the team relies on, while a typical CRUD service with a pooled database rarely gains much, because its throughput is limited by the database, not by threads. Spring MVC on virtual threads can give similar concurrency with the current code, so the decision should come from a realistic benchmark and a profile of where time goes, weighed against the rewrite effort, harder debugging and the team's experience.
What to remember
In this answer, we evaluated a proposal to rewrite a JPA CRUD service in WebFlux. A real rewrite needs R2DBC and gives up lazy loading, dirty checking and much of JPA's mapping, while the service's throughput is usually limited by the database and its pool, not by threads. MVC with virtual threads offers similar concurrency with the existing code. We set up a fair benchmark from production load, profiled where time goes, weighed the rewrite effort, debugging cost and team experience, and recommended virtual threads first, with WebFlux only for a measured large gain or streaming workloads.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would ask for evidence before approving it. JPA is blocking, so a real WebFlux version needs R2DBC and loses lazy loading, dirty checking and much of the mapping the team relies on, while a typical CRUD service with a pooled database rarely gains much, because its throughput is limited by the database, not by threads. Spring MVC on virtual threads can give similar concurrency with the current code, so the decision should come from a realistic benchmark and a profile of where time goes, weighed against the rewrite effort, harder debugging and the team's experience.
Why this question is asked
Rewrite proposals like this one come up regularly, often after a conference talk or a benchmark blog post. They are tempting because reactive stacks really do scale better for some workloads. Interviewers ask this scenario to see whether we can evaluate a technology choice by the numbers and costs specific to this service rather than by general claims. In this answer, we will clarify what the rewrite actually involves, find out where time goes in a typical request, compare the alternative of virtual threads, set up a fair benchmark, and list the costs before reaching a recommendation.
1What the Rewrite Really Involves
Changing controllers to return Mono and Flux is the easy part. The service uses JPA, the standard Java persistence API, here implemented by Hibernate, and JPA is built on JDBC, which blocks the calling thread. Running JPA calls inside WebFlux would mean wrapping each one in subscribeOn(Schedulers.boundedElastic()), which keeps the blocking and adds overhead. A real reactive version needs R2DBC, the reactive database API, with Spring Data R2DBC on top.
R2DBC is not a drop-in replacement. Spring Data R2DBC is a simpler mapper: there is no lazy loading of relationships, no dirty checking that writes changed fields automatically at commit, no first-level cache, no cascades and no JPQL. Every association becomes an explicit query and every update an explicit save. For a service with a rich entity model, that is a rewrite of the data layer, not a port.
Notice how much behaviour moves from the framework into our code. Multiply that by every entity and repository method.
2Where Does the Time Go in a CRUD Request?
Before any rewrite, we profile a few representative endpoints under load. In a typical CRUD service, a request spends most of its time waiting for PostgreSQL, a few milliseconds per query, and a little time on JSON and business logic. The database has a connection pool, say 20 connections, and the database server itself can handle only so many queries at once.
This is the key point. Reactive programming saves threads while waiting. If 200 requests are in flight and only 20 can use the database at a time, the other 180 wait for a connection whether they wait on a blocked thread or as a pending Mono. Throughput is capped by the pool and the database, so freeing threads changes little. Gains from WebFlux appear mainly with high concurrency and slow I/O that is not pooled, such as calls to slow external APIs, streaming, or thousands of long-lived connections.
- Tomcat thread or event loopa few microseconds to route the request
- Controller and JSON mappingabout 1 ms of CPU
- Wait for a pooled connectiongrows when 20 connections are all busy
- PostgreSQL queryabout 3 to 10 ms, the main cost
- Commit and responseabout 1 ms
5 layers, from the top down. Step through them one at a time.
If the database is the bottleneck, changing the thread model barely moves throughput.
3The Alternative: MVC on Virtual Threads
Java 21 made virtual threads final. They are threads managed by the JVM rather than the operating system, cheap enough to have one per request even at tens of thousands of requests. When a virtual thread blocks on JDBC, the JVM parks it and uses the underlying carrier thread for other work. In Spring Boot 3.2 and later, a single property enables them for request handling.
That gives the main benefit people expect from WebFlux, high concurrency without a large thread pool, while keeping JPA, @Transactional, readable stack traces and the existing tests. One thing to check is pinning: on Java 21, a virtual thread blocked inside a synchronized block holds its carrier thread, which some older JDBC drivers did; Java 24 and later removed most of this, so Java 25 is the better runtime for it.
4Running a Fair Benchmark
If the team still believes WebFlux will help, we test it rather than argue. We pick the two or three busiest endpoints and build a small prototype in each style: the current MVC service, the same with virtual threads, and a WebFlux plus R2DBC version. We run them against the same PostgreSQL with realistic data and a load profile taken from production, for example 1,500 requests per second with the real mix of reads and writes, and we compare throughput, p50 and p99 latency, CPU and memory at the same concurrency.
We also include a stress run beyond the peak and a run with a slowed database, because behaviour under strain is where models differ most. If WebFlux wins clearly at the load we actually expect, the case is made. In most CRUD services the three versions end up close, with the database as the limit.
5Weighing the Costs and Recommending
Even a measured gain has to pay for the rewrite. The costs are months of developer time to rewrite the data layer and tests, a period of two code bases, a steeper learning curve for everyone who joins later, stack traces that show operator internals instead of our methods, and context such as transactions, security and logging MDC that must be carried in Reactor's context rather than in thread-locals. If the team has little reactive experience, incidents also take longer to diagnose.
So my recommendation for a typical JPA-backed CRUD service is to enable virtual threads on the existing MVC service, measure, and tune the database and queries, which is usually where the real gains are. I would support WebFlux only if the benchmark shows a large benefit at the expected load, or if the roadmap adds workloads where reactive is clearly better, such as streaming large results or many long-lived connections.
6Follow-up questions
Could we keep JPA and just wrap it in boundedElastic?
It works technically, but it gives the costs of reactive without its benefits: every request still blocks a thread, now on a smaller pool, and adds thread hops and operator overhead. It is a reasonable bridge for one legacy call in an otherwise non-blocking service, not a way to make a JPA service reactive.
What if the service also calls slow external APIs?
Then concurrency matters more, because requests spend time waiting outside the pooled database. Virtual threads handle that well too, since each waiting request costs only a parked virtual thread. WebFlux becomes more attractive when the service fans out to many calls per request or streams responses, where its composition and backpressure help.
How would you present the decision to the team?
As a short written comparison with the benchmark numbers, the list of JPA features we would lose, an estimate of the rewrite effort, and the virtual-threads alternative. Showing the data lets the team reach the conclusion together, and it leaves a record for the next time the idea comes up.
7Conclusion
In this answer, we evaluated a proposal to rewrite a JPA CRUD service in WebFlux. A real rewrite needs R2DBC and gives up lazy loading, dirty checking and much of JPA's mapping, while the service's throughput is usually limited by the database and its pool, not by threads. MVC with virtual threads offers similar concurrency with the existing code. We set up a fair benchmark from production load, profiled where time goes, weighed the rewrite effort, debugging cost and team experience, and recommended virtual threads first, with WebFlux only for a measured large gain or streaming workloads.
Open with
I'd evaluate it with numbers before agreeing. First, what the rewrite really means: JPA is blocking, so a genuine WebFlux version needs R2DBC with Spring Data R2DBC, and that loses lazy loading, dirty checking, cascades and JPQL.
Then, if they want more
Every association becomes an explicit query and every update an explicit save, so it's a rewrite of the data layer, not just changing return types. Wrapping JPA in boundedElastic wouldn't count; that keeps the blocking and adds overhead. Second, would it help?
For typical CRUD, most request time is spent in PostgreSQL, and throughput is capped by the connection pool and the database. Reactive saves threads while waiting, but if only 20 connections exist, the other requests wait either way. WebFlux gains show up with high concurrency and slow unpooled I/O, streaming or long-lived connections.
Third, the alternative: Spring MVC with virtual threads, one property in Boot 3.2 and later, gives cheap blocking and high concurrency while keeping JPA, transactions and readable stack traces, ideally on Java 24 or later to avoid pinning.
Then I'd benchmark the busiest endpoints in three versions, current MVC, MVC with virtual threads and a WebFlux prototype, using production-like load and a slowed-database run, and profile where time goes. And I'd put the costs next to the results: months of rewrite, harder debugging, context propagation, and the team's reactive experience.
Unless the benchmark shows a big win at our real load, I'd enable virtual threads and tune queries instead.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21, Java 24, Java 25, Spring Boot 3.2
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Spring WebFlux, Project Reactor reference guide
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A team proposes rewriting a CRUD service backed by PostgreSQL and JPA from MVC to...": https://scrivio-interview-library.netlify.app/spring-boot/webflux/3cf85258d8/