Quick revision
The short answer
What is missing is the connection request timeout: the time a thread may wait to get a connection from the HTTP client's pool, which is separate from the connect and read timeouts and only starts once a connection is leased. If it is unset or long, threads queue for the pool for a long time while the few pooled connections are stuck on 5 second reads. The fix is a short pool acquisition timeout and a pool sized for expected concurrency, plus a bulkhead or concurrency limit per dependency so one dependency cannot take all threads, and pool metrics for leased and pending connections so we see it earlier.
What to remember
In this answer, we saw that the 5 second read timeout was working but only applied to the 20 leased connections, while the other threads waited in the pool's queue, which is governed by the separate connection request timeout. We fixed it with a short acquisition timeout and a pool sized by Little's law, added a bulkhead so one dependency can never take all threads, and exposed leased and pending pool metrics so the next degradation shows up as an alert.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
What is missing is the connection request timeout: the time a thread may wait to get a connection from the HTTP client's pool, which is separate from the connect and read timeouts and only starts once a connection is leased. If it is unset or long, threads queue for the pool for a long time while the few pooled connections are stuck on 5 second reads. The fix is a short pool acquisition timeout and a pool sized for expected concurrency, plus a bulkhead or concurrency limit per dependency so one dependency cannot take all threads, and pool metrics for leased and pending connections so we see it earlier.
Why this question is asked
This is a good debugging question: the team set a read timeout and still lost the service. The thread dump points at the real gap: threads were not waiting on the network at all, they were waiting in a queue inside the HTTP client. Interviewers want to see whether we can read that clue and understand how a connection pool behaves under a slow dependency. In this answer, we will recap how a pooled HTTP client works, do the arithmetic of the outage, read the thread dump, add the missing timeout and right-size the pool, put a bulkhead around the dependency, and expose the metrics that would have warned us.
1A Quick Recap of Pooled HTTP Clients
Clients such as Apache HttpClient keep a pool of open connections to each target host, called a route, so they do not pay for a new TCP and TLS connection on every call. A thread that wants to make a call first leases a connection from the pool, uses it for the request and response, and returns it. The pool has limits: a maximum total number of connections and a maximum per route. Apache HttpClient 5's pooling connection manager has defaults of 25 in total and 5 per route, unless configured, and those small defaults surprise many teams.
When all connections for a route are leased, the next thread has to wait for one to be returned. That wait is governed by its own setting, the connection request timeout. The connect timeout only starts when a connection is being opened, and the read timeout only starts once a leased connection is sending a request. Waiting in the pool is covered by neither.
2The Arithmetic of the Outage
Let us put numbers on it. The service runs on Tomcat with 200 request threads. The pool allows 20 connections to the dependency. Normally a call takes 50 ms, so 20 connections can serve 400 calls per second, far above the 100 per second we need.
Now the dependency degrades and every call runs into the 5 second read timeout. Each connection is busy for 5 seconds per call, so the pool can only complete 20 calls every 5 seconds, which is 4 per second. Requests needing the dependency still arrive at 100 per second, so 96 per second join the queue for the pool. In about two seconds, all 200 Tomcat threads are waiting there. With a long or infinite connection request timeout, they wait until a connection frees up, which is behind hundreds of other threads. Requests that do not need the dependency at all find no free thread either.
7 messages in order. Play them, or step through them one at a time.
The read timeout works, but it only frees 4 threads per second.
3Reading the Thread Dump
The thread dump is what tells us where the time goes. If threads were waiting on the network, their stacks would end in socket reads. Here they end in the pool's lease logic, parked and waiting for a connection to be released.
Notice the two numbers. The 20 threads in socket reads are exactly the pool size: those are the leased connections waiting for the slow dependency, and their read timeout is working. The other 180 are queued behind them. So the read timeout is not the missing piece; the missing piece is a limit on how long a thread may wait in that queue.
4Fix 1: A Short Acquisition Timeout and a Right-Sized Pool
We set the connection request timeout to a short value, such as 200 to 500 ms. When the pool is exhausted, extra threads now fail fast and return a quick error or fallback, so the service keeps its threads for other work.
We also size the pool from expected concurrency, which follows Little's law: concurrent calls equal arrival rate times call duration. At 100 calls per second and a normal p99 of 150 ms, about 15 calls are in flight at once, so 20 per route gives headroom.
5Fix 2: A Bulkhead per Dependency
A short acquisition timeout already limits how long threads wait, but under heavy load many threads can still be tied up briefly at once. A bulkhead, named after the walls that keep a ship's flooded compartment from sinking the rest, limits how many threads may be inside calls to one dependency at the same time. Calls beyond the limit are rejected immediately.
Now the worst case for the whole service is bounded: a slow payments dependency can occupy at most 25 threads, whatever happens. A circuit breaker on the same calls can then stop calling the dependency for a while when most calls fail.
6Seeing It Earlier With Pool Metrics
This outage was visible minutes before it became total, if we had been looking at the pool. Micrometer can bind Apache HttpClient's connection manager and publish the number of leased, available and pending connections per pool (check your version for the binder and metric names). A healthy pool has some idle connections and zero pending. A rising pending count, with leased equal to the maximum, is the early warning.
We alert when pending stays above zero for more than a minute. With that signal, the next degradation shows up as a clear alert naming the dependency, instead of a frozen service and a thread dump.
| Metric | Healthy | During the outage |
|---|---|---|
| Leased connections | 5 of 20 | 20 of 20 |
| Available connections | 15 | 0 |
| Pending (threads waiting) | 0 | 180 |
| Acquisition timeouts per minute | 0 | thousands, once the timeout is set |
7Follow-up questions
Why not raise the pool size to 200?
Because the bottleneck is the slow dependency, not the pool. A bigger pool lets more threads wait 5 seconds on reads, sends more load to a service that is already struggling, and still exhausts our threads. The pool should match normal concurrency, with timeouts and a bulkhead handling the abnormal case.
Would virtual threads have saved us?
They would remove the limit of 200 threads, but the calls would still pile up, now as thousands of virtual threads waiting on the same pool and the same slow dependency, holding memory and request state. Timeouts and concurrency limits are still needed; virtual threads change the cost of waiting, not the need to limit it.
8Conclusion
In this answer, we saw that the 5 second read timeout was working but only applied to the 20 leased connections, while the other threads waited in the pool's queue, which is governed by the separate connection request timeout. We fixed it with a short acquisition timeout and a pool sized by Little's law, added a bulkhead so one dependency can never take all threads, and exposed leased and pending pool metrics so the next degradation shows up as an alert.
Open with
The thread dump is the clue: the threads are parked in the pool's lease method, not in socket reads. The read timeout only applies once a thread has a connection, and connect timeout only while opening one.
Then, if they want more
Waiting for a connection from the pool has its own setting, the connection request timeout, and it is unset or long here.
So with, say, a pool of 20 and a dependency that now takes 5 seconds per call, the pool completes only 4 calls a second, while 100 a second arrive, and within a couple of seconds all 200 Tomcat threads are queued for the pool.
I would count the stacks to confirm: about 20 threads in socket reads, which is the pool size, and the rest in lease. The fix has several parts. Set a short connection request timeout, a few hundred milliseconds, so threads fail fast when the pool is exhausted.
Size the pool for normal concurrency using rate times latency, and check the defaults, since Apache HttpClient 5 allows only 5 connections per route unless configured; making it huge would only push more load onto the failing dependency.
Add a bulkhead per dependency, for example a Resilience4j semaphore bulkhead of 25 with no waiting, so one dependency can never take all threads, ideally with a circuit breaker. And expose pool metrics, leased, available and pending, with an alert on pending above zero, so we see it before the service freezes.
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.
- Official documentation
- Spring Cloud documentation, Resilience4j documentation
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 service's thread pool is exhausted during a partial outage of a downstream dependency...": https://scrivio-interview-library.netlify.app/spring-boot/resilience/d581ab87b9/