Scrivio Interview library
ConceptIntermediate6 min read · updated 12 November 2026

Compare virtual threads with reactive programming (for example Project Reactor and WebFlux) for a typical request-response service.

Both virtual threads and reactive programming let a service keep many requests waiting on I/O without needing an operating system thread for each one. Virtual threads do it while keeping ordinary sequential, blocking code, normal stack traces, debuggers and profilers, and they work with blocking JDBC and HTTP clients. Reactive code, such as Project Reactor in WebFlux, does it with a different, callback-based programming model that needs non-blocking drivers throughout, but in exchange offers built-in backpressure, streaming operators and fine control over scheduling, which still makes it a better fit for streaming and event processing.

Why this question is asked

For about ten years, the standard advice for high-concurrency Java services was to go reactive, because platform threads were too expensive to have one per waiting request. Virtual threads changed that trade-off, and many teams now ask whether reactive is still worth its cost. Interviewers ask this comparison to see whether we can weigh both approaches honestly rather than picking a side. In this answer, we will recap the problem both solve, write the same endpoint in both styles, compare debugging and libraries, look at what reactive still does better, and end with a way to choose.

1A Quick Recap of the Problem Both Solve

A typical request-response service spends most of each request waiting: for the database, for another service, for a cache. In the classic thread-per-request model each waiting request holds a platform thread, an operating system thread with its own stack, and a service can afford only a few hundred of those. Under high concurrency the threads run out long before the CPU does.

Reactive programming solves this by never blocking. A request registers what should happen when the data arrives and returns its thread at once; a few event loop threads, typically one per core, run all the callbacks. Virtual threads solve it in the opposite way: the code still blocks, but blocking is cheap, because the JVM unmounts the waiting virtual thread from its carrier and parks it in the heap.

2The Same Endpoint in Both Styles

Here is an endpoint that loads a customer and their latest orders, then calls a pricing service. First with WebFlux and Reactor, then with Spring MVC on virtual threads.

Java
// WebFlux + Reactor: non-blocking drivers (R2DBC, WebClient) are required
@GetMapping("/summary/{id}")
Mono<Summary> summary(@PathVariable long id) {
return customers.findById(id) // Mono<Customer>
.zipWith(orders.findLatest(id).collectList()) // Flux<Order> -> Mono<List<Order>>
.flatMap(t -> pricing.quote(t.getT2()) // WebClient call, Mono<Quote>
.map(q -> new Summary(t.getT1(), t.getT2(), q)));
}
// Spring MVC on virtual threads: blocking JDBC and RestClient are fine
@GetMapping("/summary/{id}")
Summary summary(@PathVariable long id) {
Customer c = customers.findById(id).orElseThrow(); // blocks; the virtual thread unmounts
List<Order> o = orders.findLatest(id);
Quote q = pricing.quote(o);
return new Summary(c, o, q);
}

Notice that the second version is just the code most of us learned to write first. Loops, try/catch, local variables and early returns work as usual. The reactive version expresses the same flow as a chain of operators, and things that are trivial in sequential code, such as a conditional call or an error handled for one step only, need specific operators. Both versions can serve thousands of concurrent requests with few OS threads.

3Stack Traces, Debuggers and Profilers

Because a virtual thread is a real java.lang.Thread, every tool that understands threads works. An exception shows the full call path from the controller to the failing line. A debugger can step through the method line by line, and a profiler attributes time to the methods that spent it. Thread dumps (in the new jcmd format) show each request's stack at the moment it was taken.

In reactive code, the method that built the pipeline has usually returned long before the pipeline runs, so an exception's stack trace shows Reactor's internal operator classes and the event loop, not the business call path. Reactor offers tools such as checkpoint() and debug agents to restore some context, but they are extra work. This difference matters most during incidents, when we need to understand quickly where time goes.

4Libraries and Drivers

A reactive pipeline is only non-blocking if every call in it is. That means R2DBC instead of JDBC, WebClient instead of a blocking HTTP client, reactive drivers for Redis, Kafka and Mongo, and great care not to call any blocking library on an event loop thread, which would stall every request it serves. Many popular libraries, such as JPA and Hibernate ORM, have no complete reactive equivalent in Spring.

Virtual threads work with the blocking libraries we already have. JDBC, JPA, RestClient and most SDKs block in ways the JVM can unmount. The remaining caveats are pinning, mainly native code on JDK 24 and later (and synchronized on JDK 21 to 23), and limits that the old thread pool used to provide, such as how many requests reach the connection pool at once.

Virtual threads vs reactive for request-response
AspectVirtual threads (MVC)Reactive (WebFlux)
Programming modelSequential, blocking styleOperator chains, callbacks
Stack traces and debuggingNormal, full call pathOperator internals; needs extra tools
DriversBlocking JDBC, JPA, RestClientNon-blocking throughout (R2DBC, WebClient)
BackpressureAdd explicitly (semaphores, limits)Built into the streams
Streaming and operatorsWrite by handRich: buffer, window, merge, retry, timeout
Scheduling controlJVM schedulerFine-grained via Schedulers

5What Reactive Still Does Better

Reactive streams have backpressure built in: a subscriber tells the publisher how many items it can take, so a slow consumer slows the producer instead of being flooded. Combined with operators for buffering, windowing, merging, throttling and timeouts, that makes reactive code well suited to streaming responses, server-sent events, WebSocket sessions and event processing pipelines that consume from one source and write to another at different speeds. With virtual threads we can build the same things, but we write the flow control ourselves with queues and semaphores.

So the honest comparison for a typical request-response service is that both handle the concurrency, virtual threads with far less complexity. For streaming and event processing with backpressure, reactive can still be the better fit.

6Follow-up questions

Is reactive faster than virtual threads?

For request-response services, benchmarks generally show them in the same range, with differences that depend on the workload and the libraries more than on the model. Neither makes a single request faster. The more important differences are in code complexity, debugging and the libraries available.

Can I mix the two in one service?

Yes, at clear boundaries. A Spring MVC service on virtual threads can still use a Reactor-based client and block on its result, which is cheap on a virtual thread. What we should avoid is blocking calls inside a reactive pipeline on event loop threads, and mixing both styles freely across the same code, which makes it hard to reason about either.

Does Kotlin coroutines change the comparison?

Coroutines give a sequential style on top of non-blocking code, which addresses much of reactive's readability cost, but they require suspend functions throughout the call path and their own debugging support. For Java code, virtual threads give a similar style without changing function signatures.

7Conclusion

In this answer, we saw that virtual threads and reactive programming both let a service handle many concurrent requests waiting on I/O without many OS threads. Virtual threads keep sequential, blocking code with normal stack traces, debuggers and profilers, and work with blocking JDBC and HTTP clients. Reactive code needs non-blocking drivers throughout and a different programming model, but provides built-in backpressure, streaming operators and fine scheduling control, which keeps it the better fit for streaming and event processing.

What to say in the interviewAbout 80 seconds aloud

Open with

Both solve the same problem: handling many concurrent requests that mostly wait on I/O, without one expensive OS thread per request. Reactive does it by never blocking: the request describes a pipeline of operators and gives its thread back, and a few event loop threads run the callbacks.

Then, if they want more

Virtual threads do it by making blocking cheap: the code blocks normally and the JVM unmounts the waiting thread from its carrier. For a typical request-response service, I prefer virtual threads because the code stays sequential. Loops, try/catch and early returns work, stack traces show the real call path, and debuggers and profilers work as usual.

They also work with blocking libraries like JDBC, JPA and RestClient, whereas a reactive service needs non-blocking drivers throughout, R2DBC and WebClient, and one accidental blocking call on an event loop stalls everything on it.

Reactive still has real strengths: backpressure built into the streams, a rich set of operators for buffering, merging, retries and timeouts, and fine control over scheduling. So for streaming responses, WebSockets or event processing where producer and consumer run at different speeds, reactive can still be the better fit. With virtual threads I would have to add limits like semaphores myself.

About this answer

Last updated
12 November 2026
Versions it names
Java 21, Java 24
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
JEP 444, Virtual Threads
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 "Compare virtual threads with reactive programming (for example Project Reactor and...": https://scrivio-interview-library.netlify.app/java/virtual-threads/9a48490e6a/