zero gravitySOLUTIONS
← All insightsBACKEND & RELIABILITY / EXPERIMENT DESIGN

Reactive Java vs. virtual threads: measure the waiting.

QUICK ANSWER

Reactive Java can help when concurrency is dominated by waiting on non-blocking I/O. It does not make CPU work disappear or guarantee full resource utilization. Compare it with a suitable blocking baseline and virtual threads under equal resource limits and realistic downstream constraints.

Inside this article 5 sections

A Java service can be slow while its CPUs look quiet. Requests may be waiting for a database, a downstream API, a connection, or a lock. In that situation, changing how the application manages waiting can matter. It still does not follow that rewriting every endpoint with Reactor will improve the product.

Reactive Java is a concurrency and composition choice, not a promise of full resource utilization. Spring WebFlux is built around non-blocking processing. Virtual threads offer another way to handle many waiting tasks while retaining a familiar sequential programming style. The useful comparison is between implementations of the same workload under the same constraints.

Find out what is consuming the request lifetime

Instrument a representative endpoint before choosing a new programming model. Separate CPU work, downstream wait, pool acquisition, and application queueing. Inspect slow requests as well as the average. A service may spend little time computing yet still be limited by a database connection pool that both a reactive and a blocking implementation must respect.

CPU-intensive transformation does not become cheaper because it appears inside a reactive chain. Likewise, a blocking driver called on an event-loop thread can undermine the concurrency design. If the application relies on blocking dependencies, include the work of isolating or replacing them in the comparison rather than benchmarking an unrealistically clean prototype.

EXPERIMENT DESIGN / SAME WORK, SAME LIMITS
Identical request mix · CPU and memory limits · downstream behavior
ABlocking baseline

Known production behavior

BVirtual threads

Sequential code, different waiting model

CWebFlux / Reactor

Non-blocking path and bounded demand

Compare completed work, tail latency, errors, memory, and recovery
A proposed experiment, not measured results. No arm is assumed to win.

Make the baseline credible

Use the same business operation, response content, database query, and downstream service behavior in each implementation. Match container limits, connection limits, and timeout policies. Record runtime and framework versions. Warm the application before measurement, then run repeated trials so a single unusually favorable run does not determine the result.

Include virtual threads when they fit the runtime and dependencies you operate. They can improve the scalability of waiting-heavy code, but they do not increase the processing power available for CPU-bound tasks. They also do not remove downstream capacity limits. A database that accepts a bounded number of useful concurrent queries still needs protection from excess demand.

A fair baseline should be reasonably configured, not intentionally constrained to make the new design look good. If one implementation uses a tiny connection pool and another uses a much larger one, you have changed more than the programming model. Record configuration differences and explain which are necessary consequences of the design.

Test ordinary traffic, slow dependencies, and overload

Begin with the expected request mix, including expensive paths and errors. Then slow a downstream dependency while keeping arrival demand controlled. Finally, exceed sustainable capacity and observe how each version behaves. Does it queue indefinitely, reject promptly, time out coherently, or consume memory until it fails?

Use a load generator that reports the offered request rate and requests it could not start. A client that waits for every response before sending more work can reduce demand automatically as the server slows, hiding the size of the overload. Keep the generator on separate resources where possible and verify that it is not the bottleneck.

Backpressure is useful only when the surrounding components honor it or define what happens when they cannot. Decide where work may buffer, where it should be rejected, and how callers learn to retry. A reactive chain does not make an unbounded external producer slow down by itself.

Read the measurements together

Measurement sheet for the experiment
MeasureWhy it changes the decision
Successful completions per secondThroughput must exclude failed or incomplete work.
Median, p95, and p99 latencyTypical speed can conceal long waits for some users.
CPU, memory, and allocation behaviorResource efficiency needs more than a thread count.
Connection wait and downstream saturationA local concurrency gain may move the bottleneck elsewhere.
Error rate and recovery after overloadStable failure behavior matters when demand exceeds capacity.
Implementation and debugging effortOperational complexity is part of the long-term cost.

Do not optimize CPU utilization toward 100 percent as an end in itself. A service needs enough headroom for bursts, background work, and failures elsewhere. Compare the cost of meeting a defined latency and reliability target at the expected load. That gives the engineering choice a business purpose.

Keep the conclusion narrower than the benchmark

If WebFlux improves this endpoint under realistic constraints, the finding applies to this tested workload and configuration. It does not prove every Java service should become reactive. If virtual threads preserve simpler code while meeting the target, that is a useful result too. If the database dominates both, improving the query may be the better next investment.

Document the experiment so another engineer can repeat it, including unsuccessful runs and known limitations. Our software architecture consulting can help define the comparison. The architecture review guide explains how to place a performance experiment inside a wider modernization decision.

To investigate whether blocking work undermines a reactive path, use Finding blocking calls in WebFlux.

FROM INSIGHT TO ACTIONSoftware architecture consulting

Design for the way your system actually works.

We help evaluate concurrency, data access, and service boundaries against your workload, with practical experiments and decisions your engineers can build on.

Explore architecture consultingDiscuss your architecture

Start with your goals.
We’ll work through the next step together.