Quick revision
The short answer
Both models can call the 10 downstream services at the same time, so the request costs roughly the slowest call rather than the sum of all ten. Reactive code does it with Mono.zip and gives us ready-made operators for timeouts, retries, backpressure and streaming; virtual threads do it with plain blocking Java on an executor or with structured concurrency, and keep normal stack traces and ThreadLocal-based tooling. We choose by the team's skills, whether we need streaming or backpressure, and which libraries we depend on.
What to remember
In this answer, we saw that the key to a 10-call aggregator with strict latency is running the calls concurrently under a deadline, and that both reactive code and virtual threads can do that. Reactive gives rich operators, backpressure and streaming at the cost of a harder mental model and harder debugging. Virtual threads keep plain Java, normal stack traces and ThreadLocal tooling, while we write the orchestration ourselves or wait for structured concurrency to leave preview. We decide by team skill, the need for streaming and backpressure, and library support.
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.
Both models can call the 10 downstream services at the same time, so the request costs roughly the slowest call rather than the sum of all ten. Reactive code does it with Mono.zip and gives us ready-made operators for timeouts, retries, backpressure and streaming; virtual threads do it with plain blocking Java on an executor or with structured concurrency, and keep normal stack traces and ThreadLocal-based tooling. We choose by the team's skills, whether we need streaming or backpressure, and which libraries we depend on.
Why this question is asked
Aggregation services, sometimes called backends for frontends, sit in front of many other services and stitch their answers into one response. Their latency budget is set by the user, not by the downstream teams, so the way we run those calls decides whether we meet a p99 target of, say, 300 ms. Interviewers ask this question because it tests whether we understand what each model actually buys us, rather than repeating that one of them is modern. In this answer, we will recap why fan-out needs concurrency, write the same aggregation twice, compare how each model handles timeouts and failures, look at debugging and tooling, and finish with how to decide.
1A Quick Recap: Why Fan-Out Needs Concurrency
Suppose each of the 10 downstream calls takes about 40 ms at the median and 120 ms at the 99th percentile. If we call them one after another, the median request takes about 400 ms and the slow tail is far worse, because every call adds its own delay. If we start all ten at once and wait for them together, the request takes about as long as the slowest single call, which is closer to 120 ms at the tail.
So the real requirement is not reactive or virtual threads. It is that the ten calls run concurrently, that we stop waiting for any of them after a deadline, and that one failing service does not block or crash the whole response. Both models can deliver that. They differ in how the code looks, how it fails, and how it behaves under load.
Two terms will come up. Blocking means a thread waits, doing nothing, until an I/O call returns. Non-blocking means the call returns immediately and the result is delivered later through a callback. Reactive programming builds on non-blocking I/O. Virtual threads, final since Java 21, keep blocking code but make the waiting thread so cheap that we can have hundreds of thousands of them.
2The Reactive Version With Mono.zip
With Spring WebFlux and WebClient, each downstream call returns a Mono, a publisher of at most one value. Nothing runs until something subscribes. Mono.zip subscribes to all of them at once and combines the results when every one has arrived.
Notice that timeouts, fallbacks and retries are operators we attach to each call: timeout(), onErrorReturn(), retryWhen(Retry.backoff(2, Duration.ofMillis(20))). That is the strength of Reactor: it has a large, tested vocabulary for exactly this kind of orchestration. If one required call fails, zip cancels the others, so we do not keep waiting for answers we will throw away.
But there is a catch: everything in the chain must be non-blocking. One blocking JDBC call or a blocking SDK inside a map() stalls an event-loop thread, and WebFlux runs on only a few of those (one per CPU core by default), so a single mistake slows every request on that thread.
3The Virtual-Thread Version With Plain Java
With virtual threads we write the same thing as ordinary blocking code. Each call runs on its own virtual thread, and when it blocks on the network, the JVM unmounts it from its carrier thread so the carrier can run other work.
8 messages in order. Play them, or step through them one at a time.
All calls start together; the deadline, not the slowest service, bounds the response.
The code reads top to bottom, a debugger steps through it line by line, and an exception has a normal stack trace that names our method. Libraries that keep context in a ThreadLocal, such as MDC logging, security context and many tracing agents, keep working because each task is a real Java thread. In Spring Boot 3.2 and later, spring.threads.virtual.enabled=true also runs request handling on virtual threads.
The cost is that we write the orchestration ourselves: deadlines, cancelling the futures we no longer need, fallbacks and retries. A library such as Resilience4j fills part of that gap. Structured concurrency is the JDK feature designed for this shape of code: a StructuredTaskScope forks subtasks, joins them, and cancels the rest when one fails or a deadline passes. It is still a preview API in Java 25, and its API changed between previews, so check its status in your JDK before relying on it in production.
4How the Two Behave Under Load and When Things Go Wrong
Under load, both models handle thousands of concurrent requests with modest memory. A reactive service keeps a small fixed number of threads and stores each request's progress in operator objects. A virtual-thread service keeps one cheap thread per request and per call, whose stack lives on the heap while it waits. For our 10-call fan-out, either one is limited far more by downstream latency and connection pools than by threads.
Backpressure is where they differ. Backpressure means the consumer tells the producer how much it can take. Reactor carries that signal through the whole chain, which matters when a downstream service streams thousands of items or when we stream a response to the client. With virtual threads we get a simpler form of backpressure: a blocked thread simply stops pulling. For request-response aggregation that is usually enough; for streaming it is not.
Failures look different too. A reactive stack trace mostly shows Reactor operator frames, and we need checkpoint() or Hooks.onOperatorDebug() to find the line that built the failing chain. A virtual-thread stack trace points straight at our code. Pinning used to be a virtual-thread trap: a thread blocking inside a synchronized block could not unmount. Java 24 removed that limitation for synchronized (JEP 491); native calls can still pin, so check your JDK version.
| Concern | Reactive (WebFlux, Reactor) | Virtual threads (MVC, RestClient) |
|---|---|---|
| Run 10 calls at once | Mono.zip, Flux.merge | executor submits or StructuredTaskScope |
| Timeouts and retries | built-in operators per call | own code or Resilience4j |
| Backpressure and streaming | end to end, first-class | only by blocking; weak for streams |
| Stack traces and debugging | operator frames; needs checkpoint() | normal traces, normal debugger |
ThreadLocal tooling (MDC) | needs context propagation | works as before |
| Blocking libraries (JDBC) | must be isolated on other schedulers | fine to call directly |
| Learning curve | steep; new mental model | low; plain Java |
5How We Would Decide
We start from the requirements, not from fashion. If the service only aggregates ten JSON responses and the team writes Spring MVC every day, virtual threads give us the concurrency we need with code everyone can read and debug at 3 a.m. We would add explicit deadlines per call, an overall deadline for the request, and a fallback for each optional section of the response.
If the service streams results to the client as they arrive, holds many long-lived connections such as server-sent events, or consumes streams that need flow control, Reactor's operators and backpressure pay for their complexity. The same is true if the team already runs reactive services well and has the tooling and habits in place.
Library support is the third test. If a key dependency only offers a blocking client, reactive code must wrap it on a bounded elastic scheduler, which brings back threads anyway. If a key dependency is reactive-only, such as some R2DBC or streaming clients, the reactive model fits better. For a new team with strict latency targets and plain request-response fan-out, our default would be virtual threads plus disciplined deadlines.
6Follow-up questions
Does virtual threads mean the downstream calls are faster?
No. A virtual thread does not make any single call faster; it makes waiting cheap so we can have many calls in flight. The latency win in this scenario comes from running the ten calls concurrently, which a platform-thread pool could also do at smaller scale. Virtual threads matter when concurrency is high enough that a pool of platform threads, each with about a megabyte of stack, would run out or need careful sizing.
How do we enforce an overall request deadline in the virtual-thread version?
We compute the deadline once when the request arrives and pass the remaining time to every Future.get call, as in the example. When the deadline passes, we cancel the futures that have not finished, which interrupts their virtual threads, and build the response from whatever arrived. With structured concurrency, a scope can carry the timeout itself and cancel all unfinished subtasks when it expires, which is less code but depends on a preview API.
What about ThreadLocal context in the reactive version?
In Reactor a request hops between threads, so a ThreadLocal set at the start is not there later. Reactor has its own Context that travels with the subscription, and Micrometer's context-propagation library, which Spring Boot 3 integrates, copies values such as trace ids and MDC entries between the Reactor Context and ThreadLocals. It works, but it is one more thing to configure and test, whereas virtual threads need nothing extra.
7Conclusion
In this answer, we saw that the key to a 10-call aggregator with strict latency is running the calls concurrently under a deadline, and that both reactive code and virtual threads can do that. Reactive gives rich operators, backpressure and streaming at the cost of a harder mental model and harder debugging. Virtual threads keep plain Java, normal stack traces and ThreadLocal tooling, while we write the orchestration ourselves or wait for structured concurrency to leave preview. We decide by team skill, the need for streaming and backpressure, and library support.
Open with
I would start by saying that the latency target is met by concurrency, not by a particular model. If the ten calls run one after another, the request costs the sum of all of them; if they run together, it costs roughly the slowest one, so both approaches must start all ten at once and stop waiting at a deadline.
Then, if they want more
In WebFlux I would build ten Monos, give each a timeout and a fallback, and combine them with Mono.zip, using the array form because the typed overloads stop at eight. Reactor gives me timeouts, retries, backpressure and streaming as operators, which is its big strength.
With virtual threads I would write plain blocking code with RestClient, submit each call to a virtual-thread-per-task executor, and wait on the futures with the remaining time until a shared deadline, cancelling whatever is late. That code reads normally, debugs normally, has real stack traces, and MDC and security context keep working because they rely on ThreadLocal.
Structured concurrency would make it cleaner, but it is still a preview API in Java 25, so I would check its status before relying on it. My decision would come down to three things: what the team knows, whether we stream results or need real backpressure, and whether our key libraries are blocking or reactive.
For plain request-response aggregation with a Spring MVC team, I would choose virtual threads with strict deadlines; for streaming or a team already fluent in Reactor, I would choose WebFlux.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21, Java 24, Java 25, Spring Boot 3
- 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 "Compare reactive programming and virtual threads for a service that aggregates data from...": https://scrivio-interview-library.netlify.app/spring-boot/reactive-testing-and-ops/9498265c34/