Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

During an incident a slow downstream service caused your service's thread pool to fill and the service stopped answering health checks. Which timeout settings and patterns would have prevented it?

The slow downstream held every request thread while it waited, so the pool filled and even health checks could not get a thread. Short connect and request timeouts based on the downstream's latency percentiles, and a pool acquisition timeout, would have bounded how long each thread could wait. A bulkhead would have capped how many threads that one downstream could use, a circuit breaker would have failed fast once it was clearly failing, deadline propagation would have stopped work for requests already abandoned upstream, and health checks that do not depend on the downstream would have kept the service from being restarted or removed for someone else's problem.

Why this question is asked

This incident pattern is so common it has a name: cascading failure. One dependency slows down, its callers run out of threads waiting for it, their callers then wait for them, and soon a problem in one small service has taken down a whole product. Interviewers ask this scenario to see whether we can explain the mechanism and pick the right protections, rather than just saying add a circuit breaker. In this answer, we will work out why the pool filled with some numbers, and then add the protections one by one: timeouts, a pool acquisition timeout, a bulkhead, a circuit breaker, deadline propagation, and health checks that measure the right thing.

1Why the Thread Pool Filled: Some Numbers

A Spring Boot service on Tomcat serves each request on a thread from a pool, 200 threads by default. Little's law, a simple rule from queueing theory, tells us how many threads are busy: requests per second multiplied by the time each request takes. Suppose our service receives 100 requests per second and each one calls a pricing service that normally answers in 50 ms. Then about 100 x 0.05 = 5 threads are waiting on pricing at any moment. Plenty of headroom.

Now pricing slows down and each call takes 30 seconds. The same 100 requests per second now need 100 x 30 = 3,000 threads. We have 200, so the pool is full after about two seconds. Every new request, including the load balancer's health check, waits in Tomcat's queue for a free thread. The health check times out, the orchestrator decides our service is dead and restarts it or takes it out of rotation, and the outage spreads, even though nothing is wrong with our own code.

Step throughHow one slow dependency takes the service down
CallersOur servicePricingHealth check
100 requests/s, each takes a thread
call pricing (now 30 s)
200 threads all waiting after ~2 s
GET /health
no free thread: probe times out
mark service unhealthy, restart
errors and retries add more load

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

Little's law: 100 requests/s x 30 s = 3,000 threads needed, only 200 available.

2Protection 1: Timeouts From the Latency Percentiles

The first fix is to bound how long each call can hold a thread. We look at pricing's real latency: say p99 is 200 ms and p99.9 is 400 ms. A request timeout of 1 second covers every healthy call with margin, and a connect timeout of 500 ms is generous inside a data centre. With these limits, the worst case is 100 x 1 = 100 threads busy on pricing, which still fits in our pool of 200, and each user gets an error or a fallback after a second instead of waiting thirty.

Notice that the timeout is chosen from the downstream's percentiles and the caller's deadline, not from a round number in a tutorial. A timeout of 30 seconds, a value many libraries and examples use, would not have helped at all here.

3Protection 2: A Pool Acquisition Timeout

HTTP clients keep a pool of connections to each destination, and a thread must borrow one before it can send a request. If the pool allows 20 connections to pricing and all 20 are busy with slow calls, the next thread waits for one to be returned. By default some clients wait indefinitely for that, which brings back the original problem through a side door. So the pool needs its own short timeout.

Java
PoolingHttpClientConnectionManager pool = PoolingHttpClientConnectionManagerBuilder.create()
.setMaxConnPerRoute(20)
.setMaxConnTotal(100)
.setDefaultConnectionConfig(ConnectionConfig.custom()
.setConnectTimeout(Timeout.ofMilliseconds(500))
.build())
.build();
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(Timeout.ofMilliseconds(100)) // wait at most 100 ms for a pooled connection
.setResponseTimeout(Timeout.ofSeconds(1)) // Apache HttpClient 5 response timeout
.build();
CloseableHttpClient http = HttpClients.custom()
.setConnectionManager(pool)
.setDefaultRequestConfig(requestConfig)
.build();

The same idea applies to database pools: HikariCP's connectionTimeout defaults to 30 seconds, which is long for an interactive request. When the pool is exhausted, failing in 100 ms tells us immediately that we are saturated, which is far more useful than a thread quietly queuing.

4Protection 3: A Bulkhead Around the Downstream

A bulkhead, named after the walls that stop one flooded compartment sinking a ship, limits how many concurrent calls one dependency may have. If only 20 threads may call pricing at once, then even if pricing hangs completely, 180 threads remain for everything else, including the pages that do not need prices and the health checks. Calls beyond the limit are rejected immediately and can use a fallback, such as showing the product without a price.

YAML
resilience4j:
bulkhead:
instances:
pricing:
max-concurrent-calls: 20 # at most 20 threads inside pricing calls
max-wait-duration: 0 # reject at once when full
circuitbreaker:
instances:
pricing:
sliding-window-size: 50
failure-rate-threshold: 50 # open when half of recent calls fail
slow-call-duration-threshold: 1s
slow-call-rate-threshold: 50 # slow calls count against it too
wait-duration-in-open-state: 10s # then let a few trial calls through

We apply both with annotations such as @Bulkhead(name = "pricing", fallbackMethod = "noPrice") and @CircuitBreaker(name = "pricing") from Resilience4j, or in code with its decorators.

5Protection 4: A Circuit Breaker That Fails Fast

Timeouts and bulkheads bound the damage, but we still spend a full second on every call to a dependency that is clearly down. A circuit breaker watches the results of recent calls, and when the failure rate or the share of slow calls passes a threshold, it opens: for the next ten seconds, calls fail immediately without touching the network. Then it lets a few trial calls through, and closes again if they succeed. Failing fast frees threads instantly, and it also gives the struggling downstream room to recover instead of being hammered by retries.

Step throughA request to pricing, with every protection
  1. Deadline already passed?
    YesStop: do no workNoContinue
  2. Circuit breaker open?
    YesFail fast, use fallbackNoContinue
  3. Bulkhead has a free slot?
    YesContinueNoReject at once, use fallback
  4. Pooled connection within 100 ms?
    YesContinueNoFail fast: pool saturated
  5. Call with connect 500 ms, request 1 smin(1 s, remaining deadline)
  6. Record success, failure or slow callfeeds the circuit breaker

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

6Protection 5: Deadline Propagation

Suppose our caller gives up after 2 seconds. If we keep working on its request for another 3 seconds, every one of those seconds is wasted, and the downstream calls we make for it add load at the worst possible moment. Deadline propagation means each request carries its deadline, the time by which an answer is useless, and every service passes the remaining time on. gRPC does this natively; with HTTP we use a header.

Java
long deadline = Long.parseLong(request.getHeader("X-Request-Deadline")); // epoch millis from the caller
long remaining = deadline - System.currentTimeMillis();
if (remaining <= 0) throw new DeadlineExceeded(); // caller has already given up
Duration timeout = Duration.ofMillis(Math.min(remaining - 50, 1_000)); // keep 50 ms for our own work
// call pricing with this timeout, and forward X-Request-Deadline unchanged

So work stops at every level once the answer can no longer be used, which is exactly when a system under stress most needs to shed load.

7Protection 6: Health Checks That Measure the Right Thing

Finally, the health check. A liveness check answers one question: is this process broken in a way that a restart would fix? A slow downstream is not such a problem, so liveness must not call pricing, or a pricing outage restarts every caller. In Spring Boot, the liveness and readiness probes are separate health groups, and we keep downstream checks out of liveness. Running the actuator on a separate management port, with management.server.port, also gives it its own small server and thread pool, so the probe still gets an answer when the main pool is full. Readiness can include critical dependencies, but carefully: if every instance becomes not ready at once, the load balancer has nowhere to send traffic.

8Follow-up questions

Would switching to virtual threads have prevented the incident?

It would have changed the symptom, not the cause. With virtual threads, 3,000 waiting requests are cheap, so the pool would not fill, but each still waits thirty seconds, holding memory and connections, and the pricing service receives even more concurrent load. The same timeouts, bulkhead and circuit breaker are still needed.

Should we retry when pricing times out?

Only carefully. A retry doubles load on a dependency that is already slow. If we retry, it should be once, with backoff and jitter, only for idempotent calls, within the remaining deadline, and never when the circuit breaker is open.

9Conclusion

In this answer, we used Little's law to see why a downstream that slowed from 50 ms to 30 seconds filled a 200-thread pool in about two seconds. We bounded each call with connect and request timeouts based on latency percentiles, added a pool acquisition timeout, isolated the dependency with a bulkhead, failed fast with a circuit breaker, propagated deadlines so abandoned work stops, and kept liveness checks independent of downstream services so a dependency's outage does not restart our own service.

What to say in the interviewAbout 80 seconds aloud

Open with

The mechanism is Little's law: threads in use equals request rate times call duration. At 100 requests per second and a 50 millisecond pricing call we use about 5 threads, but when pricing takes 30 seconds we would need 3,000, so a 200-thread Tomcat pool fills in a couple of seconds and even the health check cannot get a thread.

Then, if they want more

First, I would set short timeouts on the pricing client from its real percentiles, for example a 500 millisecond connect timeout and a one second request timeout if p99.9 is 400 milliseconds, plus a pool acquisition timeout of around 100 milliseconds, so threads never wait indefinitely for a connection.

Second, a bulkhead that allows only, say, 20 concurrent calls to pricing, so the rest of the service keeps working and excess calls get a fallback. Third, a circuit breaker that opens when failures or slow calls pass a threshold, so we fail fast and give pricing room to recover.

Fourth, deadline propagation, passing the caller's deadline downstream and stopping work once it has passed. And finally, health checks: liveness should never depend on a downstream, and I would run the actuator on a separate management port so probes are answered even when the main pool is busy.

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 "During an incident a slow downstream service caused your service's thread pool to fill...": https://scrivio-interview-library.netlify.app/java/networking/92d7d41b68/