Scrivio Interview library
DesignPrincipal6 min read · updated 12 November 2026

Your organisation has 150 reactive services and is considering a gradual move toward virtual threads. How would you use testing (StepVerifier suites, contract tests, load tests) to make that migration safe over several years?

I would treat the existing StepVerifier and WebTestClient suites as the description of current behaviour, but put the safety net at the HTTP and messaging level: black-box contract and integration tests written before a service migrates, so the new virtual-thread implementation is checked against the same expectations. Load tests compare latency, throughput and resource use before and after, the switch happens behind feature flags or with traffic shadowing where possible, and reactive-specific tests are retired only after replacement tests cover the same cases.

Background to this question

Migrating 150 services from WebFlux to Spring MVC on virtual threads over several years is mostly a rewrite of internals while the outside must stay the same. The danger is not that the new code is worse, it is that it is subtly different: an error that used to return 503 now returns 500, a stream that used to emit incrementally now buffers, a timeout that used to be 2 seconds is now the default 30. Unit tests do not catch these differences, because the unit tests themselves are rewritten along with the code. In this answer, we will see why reactive unit tests cannot be the safety net, build black-box tests that survive the rewrite, compare performance with load tests, switch traffic safely, and decide when old tests can go.

1Why Reactive Unit Tests Are Not Enough

A StepVerifier test checks a method that returns a Mono or Flux. After migration, the same method returns a plain object or a List, so every such test must be rewritten. A rewritten test proves that the new code matches the new test; it does not prove that the new code matches the old behaviour, because the person rewriting both can carry the same misunderstanding into each.

So the existing suites are valuable as documentation: they tell us which behaviours were considered important, including error cases and edge cases. But the safety net must be something that does not change when the implementation does. That means tests at the boundary of the service, its HTTP API and its messages, which look identical whether the inside is reactive or not.

2Black-Box Contract and Integration Tests Before Migrating

Before a service migrates, the team writes or strengthens black-box tests that talk to it only over HTTP and messaging: start the service in a container or on a random port, with real databases in Testcontainers and downstream services replaced by WireMock, then send requests and assert on responses, status codes, error bodies, headers, timing limits and messages produced. Consumer-driven contract tests, with a tool such as Spring Cloud Contract or Pact, add the expectations of the service's clients.

Java
// Runs unchanged against the WebFlux version and the virtual-thread version
@Test
void unknownOrderReturnsProblemDetails() {
RestAssured.given().baseUri(serviceUrl)
.when().get("/orders/999")
.then().statusCode(404)
.contentType("application/problem+json")
.body("code", equalTo("ORDER_NOT_FOUND")); // same contract, any implementation
}
@Test
void slowPricingTimesOutWithin2Seconds() {
pricingMock.stubFor(get(urlPathMatching("/prices/.*")).willReturn(ok().withFixedDelay(5_000)));
long start = System.nanoTime();
RestAssured.given().baseUri(serviceUrl).get("/orders/42/total").then().statusCode(503);
assertThat(Duration.ofNanos(System.nanoTime() - start)).isLessThan(Duration.ofMillis(2_500));
}
Step throughMigrating one service safely
  1. Inventory behaviours from existing reactive testserrors, timeouts, streaming, empty cases
  2. Write black-box contract and integration testsrun green against the reactive version
  3. Baseline load testp50, p99, throughput, CPU, memory, pools
  4. Build the virtual-thread versionsame tests must pass
  5. Shadow traffic or flag a small sharecompare responses and metrics
  6. Do results match the baseline?
    YesIncrease traffic, then switch fullyNoFix and repeat
  7. Retire reactive-only testsonly when black-box tests cover their cases

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

Notice the second test. Timeouts, retries and fallbacks are exactly the behaviours that change silently in a rewrite, because in reactive code they are operators and in imperative code they are client settings. The existing reactive tests tell us which ones exist; the black-box tests pin them down. A good rule is that every StepVerifier test of an error or timing behaviour should have a black-box counterpart before migration starts.

3Comparing Performance With Load Tests

The point of the migration is usually simpler code and easier operations, not speed, but we must know it is not a regression. The baseline load test runs against the reactive version at realistic and peak rates and records p50 and p99 latency, throughput at a fixed CPU budget, memory, connection pool usage and error rates. The same test, unchanged, runs against the new version on the same hardware.

Virtual threads change where limits sit. A reactive service bounded its concurrency through operator concurrency arguments and connection pools; a virtual-thread service will happily start ten thousand concurrent requests and hit the database pool instead. So the load test should include an overload phase, say twice peak, and check that the new version sheds load as gracefully as the old one, through explicit limits rather than collapse.

Example before and after comparison at 3,000 requests per second
MeasureWebFluxVirtual threads
p50 latency18 ms19 ms
p99 latency85 ms92 ms
CPU at peak54 percent58 percent
Heap used610 MB700 MB
Errors at 2x peak2 percent 503smust be similar, not timeouts
Illustrative numbers; agree acceptable differences before the test, not after.

4Switching Traffic Safely

Even with good tests, production traffic contains cases nobody wrote down. Where possible, the new version first receives shadow traffic: a copy of real read requests, whose responses are compared with the reactive version's and then discarded. Differences are logged and investigated. For writes, shadowing is risky, so the switch happens behind a feature flag or at the load balancer, sending 1 percent, then 10, then 50, then all traffic to the new version while comparing error rates and latency dashboards, with an instant way back.

Over several years, this process repeats 150 times, so the platform team turns it into tooling: a shadowing proxy, a standard load test harness, a dashboard comparing two versions of a service. The first few migrations are slow and teach the process; later ones follow a runbook.

5When Reactive Tests Can Be Retired

Reactive-specific tests, the StepVerifier and virtual time tests, cannot run against imperative code, so they are deleted as the code they test disappears. The rule is that a reactive test is deleted only when its case is covered by a black-box test or by a new unit test of the replacement code, and the reviewer checks the mapping. A simple way to keep this honest is a migration checklist per service that lists each behaviour from the inventory and the test that now covers it. When the list is complete and the service has run on the new stack for a few weeks without regressions, the reactive version and its tests are removed.

6Follow-up questions

What if a service streams responses with Server-Sent Events?

Then the black-box tests must check streaming behaviour: that the first event arrives before the last is produced, and how the stream ends on error. Spring MVC can stream with SseEmitter or a streaming response body, but the behaviour differs in details, so streaming services are good candidates to migrate late, or to keep reactive.

Should every one of the 150 services migrate?

No. The testing process gives us data per service. Services that are stable, rarely changed and perform well may stay reactive indefinitely. Migration effort goes where reactive complexity causes the most cost, such as frequent incidents or slow onboarding.

How do you keep the contract tests from becoming a maintenance burden?

Keep them few and focused on the API's promises, such as status codes, error formats, key fields, timeouts and messages, rather than every detail. Run them in CI for every change, not only during migration, so they stay useful as the regular regression suite afterwards.

7Conclusion

In this answer, we used testing to make a multi-year move from reactive services to virtual threads safe. Existing StepVerifier and WebTestClient suites tell us which behaviours matter, but the safety net is black-box contract and integration tests at the HTTP and messaging level, written before migration so they check both versions against the same expectations. Load tests compare latency, throughput and resources and check overload behaviour, traffic moves through shadowing or feature flags, and reactive-specific tests are retired only when replacement tests cover the same cases.

What to say in the interviewAbout 90 seconds aloud

Open with

The key idea is that unit tests get rewritten along with the code, so they cannot prove the behaviour stayed the same. I would treat the existing StepVerifier and WebTestClient suites as an inventory of what matters, especially error paths, timeouts, empty results and streaming, and then move the safety net to the boundary.

Then, if they want more

Before a service migrates, the team writes black-box contract and integration tests that only talk HTTP and Kafka, with Testcontainers for the database and WireMock for dependencies, and those tests must pass against the reactive version first. Timeouts and fallbacks deserve particular attention, because they are operators in reactive code and client settings in imperative code, so they change silently.

Next, a baseline load test records p50 and p99 latency, throughput, CPU, memory and pool use, including an overload phase, because virtual threads move the concurrency limit to the connection pool. The new version must pass the same black-box tests and the same load test within differences we agreed up front.

Then traffic moves gradually, with shadowing for reads and feature flags or weighted routing for writes, with an easy rollback. Reactive tests are only deleted when a checklist shows each behaviour is covered by a black-box or new unit test.

Over 150 services, the platform team turns this into tooling and a runbook, and services without a good reason to move can stay reactive.

About this answer

Last updated
12 November 2026
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 organisation has 150 reactive services and is considering a gradual move toward...": https://scrivio-interview-library.netlify.app/spring-boot/reactive-testing-and-ops/f9698d053b/