Scrivio Interview library
ScenarioIntermediate6 min read · updated 12 November 2026

A Spring Boot service on Tomcat with 200 threads calls a fast payments API and a slow reporting API. When reporting slows down, payments requests also time out. How would you isolate them, and does moving to virtual threads change the picture?

When reporting slows down, its calls hold Tomcat request threads while they wait, and once most of the 200 threads are stuck on reporting, payments requests queue behind them and time out. We isolate them with a bulkhead that caps concurrent reporting calls, separate HTTP connection pools per dependency, strict timeouts on reporting, and fast failure when the limit is reached. Virtual threads remove the thread count as the scarce resource, but connections, memory and the downstream service's capacity are still limited, so we keep the concurrency limits and monitor concurrent calls per dependency.

Why this question is asked

This scenario describes one of the most common production incidents in Spring Boot services: the endpoint that broke is not the one that slowed down. It also has a modern twist, because many teams expect virtual threads to make the problem go away. Interviewers use it to check that we can reason about resources with numbers and that we know what virtual threads do and do not change. In this answer, we will work out why payments fail, isolate the two dependencies step by step, and then see what changes, and what does not, with virtual threads.

1A Quick Recap of How Tomcat Uses Threads

With Spring MVC on Tomcat, each incoming HTTP request is handled by one thread from Tomcat's pool, 200 threads by default (server.tomcat.threads.max). That thread runs our controller, makes any outgoing calls, waits for their answers, and writes the response. When all 200 are busy, new requests wait in Tomcat's accept queue, and if they wait too long, the client or load balancer times out.

A thread that is waiting for a slow HTTP response is doing nothing useful, but it is still taken. That is the root of this incident.

2Why Payments Fails When Reporting Slows Down

Let us put numbers on it with Little's law, which says that the average number of requests in progress equals the arrival rate times the average time each one takes.

Java
normal: reporting 20 req/s x 0.2 s = 4 threads busy
payments 100 req/s x 0.05 s = 5 threads busy // 9 of 200 used
reporting slows to 10 s:
reporting 20 req/s x 10 s = 200 threads busy // every thread
payments 100 req/s -> no free thread, requests queue and time out
Tomcat's 200 threads before and after the slowdown
SituationReporting threadsPayments threadsFree
Normal45191
Reporting at 10 s, no limits2000 (queued)0
Reporting at 10 s, bulkhead of 20205175

Notice that payments did not get slower at all. The payments API still answers in 50 ms. But payments requests cannot start, because there is no thread to run them. Within about ten seconds of the slowdown, reporting calls have taken every thread, and the whole service looks down.

3Isolating the Dependencies

The fix has four parts that work together. First, a bulkhead on reporting calls caps how many may be in progress at once. With a semaphore bulkhead of 20, the 21st concurrent reporting call is rejected immediately, so reporting can never hold more than 20 of the 200 threads. Second, separate HTTP connection pools for each dependency, so slow reporting connections cannot starve the payments client of connections. Third, a strict timeout on reporting calls, for example 2 seconds, so even the 20 permitted calls give their threads back quickly. Fourth, fail fast when the limit is reached, with a fallback that returns an empty or cached report or a 503, instead of waiting.

Java
resilience4j:
bulkhead:
instances:
reporting:
max-concurrent-calls: 20
max-wait-duration: 0ms
@Bean
RestClient reportingClient(RestClient.Builder builder) {
var pool = PoolingHttpClientConnectionManagerBuilder.create()
.setMaxConnTotal(20).setMaxConnPerRoute(20).build(); // reporting's own pool
var http = HttpClients.custom().setConnectionManager(pool).build();
var factory = new HttpComponentsClientHttpRequestFactory(http);
factory.setConnectTimeout(Duration.ofSeconds(1));
factory.setReadTimeout(Duration.ofSeconds(2)); // strict timeout
return builder.requestFactory(factory).baseUrl("http://reporting").build();
}
@Bulkhead(name = "reporting", fallbackMethod = "noReport")
public Report report(String id) { return reportingClient.get().uri("/reports/{id}", id).retrieve().body(Report.class); }
Report noReport(String id, BulkheadFullException e) { return Report.unavailable(id); } // fast fallback

With these limits, a reporting slowdown costs at most 20 threads for at most 2 seconds each. Payments keeps its threads and its own connections, so it is unaffected. Reporting users see a degraded report instead of a hang, which is the honest outcome when reporting is broken. The exact setter names on the request factory vary between Spring and HttpClient versions, so check your version.

4What Changes With Virtual Threads

With spring.threads.virtual.enabled=true on Java 21 or later, Tomcat runs each request on a virtual thread, a lightweight thread managed by the JVM that releases its carrier thread while it waits on I/O. We can have hundreds of thousands of them, so the 200-thread limit disappears, and payments requests no longer starve for threads.

But the problem has only moved. Without a limit, 20 requests per second to a reporting API that takes 10 seconds means 200 concurrent reporting calls after ten seconds, 2,000 if it takes 100 seconds, and nothing stops the growth. Each call holds an HTTP connection, so the connection pool is now the scarce resource. Each holds memory for its request and partial response. And all of them land on the reporting service, which is already struggling, so we push it further into overload. The scarce resource changed from threads to connections, memory and downstream capacity, so concurrency limits remain necessary. The semaphore bulkhead fits virtual threads well, because it limits concurrency without needing a thread pool.

What is scarce?
ResourcePlatform threads (200)Virtual threads
Request threadsscarce: 200effectively unlimited
HTTP connectionsscarcescarce
Memory per in-flight callbounded by 200grows without a limit
Downstream capacityscarcescarce, and now easier to overload

5Monitoring Concurrent Calls per Dependency

Finally, we make the isolation visible. Resilience4j publishes bulkhead metrics, such as available concurrent calls, and rejected calls appear in call metrics. The HTTP client's connection pool exposes leased and pending connections, and Tomcat exposes busy threads. A dashboard with concurrent calls per dependency shows at a glance which dependency is filling up, long before users notice, and an alert on rejected calls tells us the bulkhead is doing its job.

6Follow-up questions

Would a thread pool bulkhead be better here?

It would isolate more strongly, because the request thread could stop waiting on a future after its own timeout. But for a synchronous MVC service, a semaphore bulkhead plus a strict read timeout gives most of the protection at much lower cost, and with virtual threads the thread pool flavour adds little.

Could we just raise Tomcat's thread count to 2,000?

That only delays the problem: at 10 seconds per call, 20 reporting requests per second fill 2,000 threads in 100 seconds. It also costs memory for each platform thread and pushes more load onto reporting. Limits per dependency fix the cause; more threads only move the cliff.

Should reporting be moved out of the request path entirely?

Often yes. If reports are slow by nature, generating them asynchronously and letting the user fetch the result later removes the coupling altogether. Bulkheads are the right immediate fix, and an asynchronous design is a good longer-term one.

7Conclusion

In this answer, we saw that a slow reporting API took every Tomcat thread, so fast payments requests could not even start. We isolated the two with a semaphore bulkhead on reporting, separate connection pools, a strict timeout and a fast fallback. Virtual threads remove the thread limit but not the limits on connections, memory and downstream capacity, so we keep the concurrency limits and watch concurrent calls per dependency.

What to say in the interviewAbout 90 seconds aloud

Open with

Tomcat handles each request on one of its 200 threads, and that thread waits while we call reporting. Normally reporting at twenty requests per second and 200 milliseconds uses about four threads, but when it slows to ten seconds, Little's law says it needs two hundred, which is every thread.

Then, if they want more

Payments itself is still fast, but its requests cannot get a thread, so they queue and time out. To isolate them, I would put a semaphore bulkhead on reporting calls, say twenty concurrent calls with no waiting, so reporting can never take more than twenty threads.

I would give each dependency its own HTTP connection pool, so slow reporting connections cannot starve payments. I would set a strict read timeout on reporting, like two seconds, so even the permitted calls release threads quickly, and when the bulkhead is full I would fail fast with a fallback, an unavailable report or a 503, instead of waiting.

With virtual threads, the thread count stops being the limit, so payments would not starve for threads. But without a bulkhead, reporting calls would grow without bound, holding connections and memory and piling more load on a reporting service that is already struggling.

So the scarce resource just moves to connections, memory and downstream capacity, and I would keep the concurrency limit. Finally I would monitor concurrent calls and rejections per dependency on a dashboard.

About this answer

Last updated
12 November 2026
Versions it names
Java 21
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 "A Spring Boot service on Tomcat with 200 threads calls a fast payments API and a slow...": https://scrivio-interview-library.netlify.app/spring-boot/resilience/5d8ee70ed3/