Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Your teams use DeferredResult, CompletableFuture, WebFlux Mono and virtual threads to handle slow downstream calls, and incidents show each style fails differently. What guidance would you give for new and existing services?

For new Spring MVC services on Java 21 or later, I would make simple blocking code on virtual threads the default for I/O-bound work, always with timeouts and bulkheads. Async MVC return types are reserved for the cases where they add value, such as long polling, server-sent events or completion by an external event, and WebFlux stays where streaming or very high concurrency with reactive drivers is needed and the team has the skills. Every style must use shared libraries for context propagation, timeouts and error mapping, and existing services migrate gradually, starting with those whose async code causes the most incidents, measured before and after.

Why this question is asked

When four ways of handling slow calls coexist, each team learns its own failure modes the hard way: lost trace ids with CompletableFuture, forgotten DeferredResults that hang, blocked event loops in WebFlux, pinned or unbounded virtual threads. The incident reviews read differently, but the root cause is the same: no shared guidance. Interviewers ask this at a senior level to see whether we can turn a mix of techniques into a clear default and a set of rules every style must follow. In this answer, we will look at how each style fails, choose the default and its exceptions, define the rules that apply to all styles, and plan the migration.

1How Each Style Fails

Each technique solves the same problem, not holding a scarce thread while waiting, and each fails in its own way. DeferredResult fails when some code path forgets to call setResult or setErrorResult, and the request hangs until the async timeout. CompletableFuture fails by losing ThreadLocal context such as the MDC and security context when it runs on the common pool, and by never completing on swallowed errors. WebFlux fails when someone calls blocking code on an event-loop thread, which stalls every request that loop serves, and through hard-to-read stack traces that slow incident response.

Virtual threads fail differently again. Because they are cheap, concurrency can rise until a downstream service or a connection pool is overwhelmed, and, on Java 21, blocking inside synchronized blocks could pin carrier threads; this was largely resolved in Java 24, so it matters much less on Java 25. The common theme is that most incidents come from missing timeouts, missing limits and missing context propagation, not from the style itself.

Typical failure by style
StyleTypical incidentGuard
DeferredResultnever completed, hangs to timeoutcomplete on every path, timeout result
CompletableFuturelost MDC and security contextcontext-propagating executor, orTimeout
WebFlux Mono/Fluxblocking call stalls the event loopBlockHound in tests, reactive drivers
Virtual threadsdownstream overwhelmed, pool exhaustedbulkheads, client timeouts

2The Default and Its Exceptions

For new Spring MVC services on Java 21 or later, preferably 25, the default is plain blocking code on virtual threads, enabled with spring.threads.virtual.enabled=true in Spring Boot 3.2 or later. The reason is simplicity: one thread per request again, so ThreadLocal context works, stack traces are readable, and there is nothing to forget to complete. For I/O-bound work, it gives most of the capacity benefit the other styles were adopted for.

Async MVC return types are allowed where they add something blocking cannot: long polling, where the request waits for an event that may take minutes; server-sent events with SseEmitter; and responses completed by an external event, such as a message arriving on a queue, with DeferredResult. WebFlux remains where there is real streaming with back-pressure, very high concurrency with reactive drivers end to end, and a team that has the skills to operate it.

Step throughChoosing the style for a slow call
  1. Is the result a stream or needs back-pressure?
    YesWebFlux, if the team has the skillsNocontinue
  2. Is it completed by an external event or long polling?
    YesDeferredResult or SseEmitterNocontinue
  3. Blocking code on virtual threadsthe default
  4. Add timeouts, bulkheads, context propagationrequired in every style

4 steps in order. Play them, or step through them one at a time.

3Rules That Apply to Every Style

Whatever the style, three things are required. Timeouts: every downstream client has a connect and read timeout, and every async request has a timeout shorter than the client's patience, so failures are fast and explicit. Context propagation: trace ids, the MDC and the security context reach every thread that does work for the request, using shared executors with Micrometer context propagation or equivalent decorators, never the common pool. Error mapping: failures, including timeouts, are mapped to consistent responses, for example a ProblemDetail with 504 for a downstream timeout, in a shared @ControllerAdvice.

Limits are the fourth rule, especially with virtual threads. A bulkhead, a cap on concurrent calls to each dependency such as a semaphore of 50 for the pricing service, prevents a slow dependency from absorbing unlimited concurrency. Connection pool sizes must match these caps.

Java
// From the shared library: one way to call a dependency in any style
Price price(String sku) {
return bulkheads.pricing().call(() -> // at most 50 concurrent calls
pricingClient.get()
.uri("/prices/{sku}", sku)
.retrieve()
.body(Price.class)); // RestClient with 2 s read timeout
}
// pricing slow -> 51st caller rejected immediately -> 503 ProblemDetail, trace id in the log

Putting these rules in shared libraries, rather than in a guideline document, is what makes them reliable. A team using the platform's HTTP client and executors gets timeouts, propagation and error mapping without having to remember them.

4Migrating Existing Services

Not every existing service should change. A WebFlux service that is stable, well understood by its team and genuinely reactive end to end stays. A DeferredResult endpoint that implements long polling correctly stays. The migration targets are services where the async code causes incidents or slows development: futures added only for capacity, reactive code wrapped around blocking libraries, or teams that no longer have the skills for the style they inherited.

We start with the services that had the most async-related incidents in the last two quarters. For each, we first add the shared timeouts and propagation, which often fixes the incidents on its own, then convert endpoints to blocking code on virtual threads where that simplifies them. Before and after, we measure p95 and p99 latency, error rate, memory and CPU under the same load test, and publish the results, so the next team can decide with evidence.

5Follow-up questions

Why not make WebFlux the default, since it handles everything?

Because its costs fall on every service while its benefits matter for few. Reactive code needs specific skills, reactive drivers throughout, and different debugging habits. For the typical I/O-bound API, virtual threads give similar capacity with code everyone can read, so making WebFlux the default would raise cost without raising value.

How do you stop teams from using CompletableFuture in new code?

Not with a ban, but by making the default easier: the service template enables virtual threads, the shared clients have timeouts and bulkheads, and the guide shows the simple version first. Reviews ask for a reason when futures appear in controllers, and an ArchUnit rule can flag supplyAsync calls without an executor.

What do you measure to know the guidance works?

The number of incidents whose root cause is async handling, per quarter; time to diagnose incidents, which improves when traces and logs are complete; and latency and resource use of migrated services compared with before.

6Conclusion

In this answer, we saw how each async style fails: DeferredResults that are never completed, futures that lose context, event loops blocked by blocking code, and virtual threads that overwhelm dependencies. The guidance makes blocking code on virtual threads the default for new I/O-bound MVC services, keeps async return types for long polling, SSE and external completion, and keeps WebFlux for streaming and reactive end-to-end needs with skilled teams. Every style must have timeouts, bulkheads, context propagation and error mapping from shared libraries, and migration proceeds service by service, starting with the most incident-prone, measured before and after.

What to say in the interviewAbout 100 seconds aloud

Open with

I'd start by pointing out that the incidents differ in shape but share causes: missing timeouts, missing limits and missing context propagation. DeferredResults hang when an error path never completes them, CompletableFutures lose the MDC and security context on the common pool, WebFlux stalls when someone blocks the event loop, and virtual threads can flood a downstream because concurrency is cheap.

Then, if they want more

So my guidance has a default and rules. The default for new MVC services on Java 21 or later, ideally 25, is plain blocking code on virtual threads, because ThreadLocal context works, stack traces are readable and there's nothing to forget to complete.

Async return types are for where they add value: long polling, server-sent events, or a result completed by an external event like a queue message. WebFlux stays for real streaming with back-pressure, or reactive end to end with reactive drivers, and only with a team that has the skills.

Then the rules for every style: timeouts on every client and async request, context propagation through shared executors, never the common pool, consistent error mapping like a 504 ProblemDetail for downstream timeouts, and bulkheads per dependency, which matter most with virtual threads. I'd put those in shared libraries so teams get them by default.

For existing services, I wouldn't rewrite stable ones. I'd start with the services with the most async incidents, add the shared timeouts and propagation first, which often fixes things alone, then simplify endpoints to virtual threads, measuring p99 latency, errors and resources before and after.

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.
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 "Your teams use DeferredResult, CompletableFuture, WebFlux Mono and virtual threads to...": https://scrivio-interview-library.netlify.app/spring-boot/mvc-architecture/699f8d2897/