Quick revision
The short answer
When our callers give up after 5 seconds but we wait up to 10 for our dependency, every slow call keeps a thread and a connection busy for up to 5 seconds on work nobody will ever receive, and under load that waste exhausts our service. Timeouts should shrink along the call chain: each hop's timeout, multiplied by its attempts and plus backoff, must fit inside its caller's budget. Better still, we propagate a deadline, for example a header carrying the remaining time, so each service can stop early, and we base every timeout on measured latency percentiles rather than round numbers.
What to remember
In this answer, we saw that an inner timeout longer than the caller's wastes threads, connections and dependency capacity on responses nobody will read, and under load turns a slow dependency into an outage. Timeouts should shrink along the chain, with each hop's attempts and backoff fitting inside its caller's budget. Propagating a deadline, such as a remaining-time header, lets each service stop early when the budget is spent, and the values themselves should come from measured latency percentiles rather than round numbers.
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.
When our callers give up after 5 seconds but we wait up to 10 for our dependency, every slow call keeps a thread and a connection busy for up to 5 seconds on work nobody will ever receive, and under load that waste exhausts our service. Timeouts should shrink along the call chain: each hop's timeout, multiplied by its attempts and plus backoff, must fit inside its caller's budget. Better still, we propagate a deadline, for example a header carrying the remaining time, so each service can stop early, and we base every timeout on measured latency percentiles rather than round numbers.
Why this question is asked
Timeouts are usually set one service at a time, by different teams, often by copying a value from another project. Nobody looks at the chain as a whole, and the result is a deep service waiting much longer than the shallow one that called it. Interviewers ask this scenario because it tests whether we think of timeouts as a budget shared along a request path, not as a local setting. In this answer, we will see exactly what goes wrong with the 5 and 10 second values, work out how to budget timeouts along a chain, propagate a deadline in code, and choose the values from real latency data.
1A Quick Recap of the Setup
We have three hops. A caller, say an API gateway, calls our order service with a 5 second timeout. The order service calls a pricing dependency with a 10 second read timeout. A timeout is a promise to stop waiting: after it fires, the waiting side gives up and returns an error. Notice that giving up only affects the side that gave up. When the gateway stops waiting after 5 seconds, the order service is not told; it keeps working on a request whose answer will be thrown away.
2What Goes Wrong With 5 and 10 Seconds
Suppose pricing becomes slow and answers after 8 seconds. At 5 seconds the gateway times out and returns an error to the user, who may click again. Our order service is still waiting, and keeps waiting for 3 more seconds, holding a request thread, a pooled connection to pricing, and any database transaction it opened. When pricing finally answers, we build a response and write it to a connection the gateway has already abandoned.
6 messages in order. Play them, or step through them one at a time.
Three seconds of work per request that nobody will receive.
Under load this waste decides whether the service survives. At 100 requests per second, every second of useless waiting holds another 100 threads. With 3 wasted seconds per request, that is 300 threads doing nothing useful, enough to exhaust a default Tomcat pool of 200 threads, after which the order service also stops answering requests that do not need pricing at all. Meanwhile users retry, which doubles the load on a dependency that was already slow. The long inner timeout turned a slow dependency into an outage of our service.
3Budgeting Timeouts Along the Chain
The rule is that timeouts shrink as we go deeper. Each hop gets a budget from its caller and spends part of it on its own work and part on its downstream calls. The downstream call's timeout, times the number of attempts, plus the backoff between them, must fit inside what is left.
Let us budget the example. The gateway allows 5 seconds. The order service needs about 300 ms for its own work and database queries at p99, and we keep 200 ms of margin for network and serialisation, so 4.5 seconds remain for pricing. If we allow one retry, two attempts plus a 250 ms backoff must fit in 4.5 seconds, so each attempt can take at most about 2.1 seconds. That is the ceiling; the actual value comes from pricing's measured latency, as we will see below, and is usually much lower.
| Hop | Budget | Spent on | Downstream timeout |
|---|---|---|---|
| Gateway -> order service | 5,000 ms | the whole request | 5,000 ms |
| Order service | 5,000 ms | 300 ms own work, 200 ms margin | 4,500 ms left for pricing |
| Order service -> pricing | 4,500 ms | 2 attempts + 250 ms backoff | at most 2,100 ms per attempt |
| Pricing -> its database | under 2,100 ms | query and processing | e.g. 1,000 ms statement timeout |
4Propagating a Deadline
Static budgets break when a request arrives late in its budget, for example after the gateway already spent 2 seconds on authentication and a slow route. A more robust approach is to propagate a deadline: the caller sends the time remaining, and each service subtracts what it has used before calling further. gRPC does this as a built-in feature; over HTTP we use a header, for example X-Request-Deadline with an absolute time, or a remaining-milliseconds header, which avoids depending on synchronised clocks.
Notice the check before the call. If the budget is already spent, we fail immediately instead of sending a request whose answer will arrive too late. Pricing can do the same with its own database query. The per-call client timeout still exists as an upper bound, so a missing header cannot make a call wait forever; we use whichever is smaller.
5Choosing Values From Measured Latency
Round numbers like 10 seconds usually mean nobody measured. We look at the dependency's latency distribution in production, for example from the http.client.requests metric, which records each call's duration. If pricing answers in 40 ms at p50, 180 ms at p99 and 600 ms at p99.9, a timeout of about 800 ms to 1 second lets virtually every healthy call finish while cutting off the calls that are stuck. A 10 second timeout on that dependency only ever matters when something is broken, and then it makes things worse.
We review the values when latency changes, after a big release or a traffic shift, because a timeout set from last year's numbers can be too tight or too loose today. And the ordering rule always holds: whatever the measured values say, an inner timeout must not exceed the time its caller is willing to wait.
6Follow-up questions
What if a dependency is legitimately slow, such as a report taking 20 seconds?
Then a synchronous call inside a 5 second budget is the wrong shape. We would make it asynchronous: accept the request, return 202 with a job id, and let the caller poll or receive a callback. Stretching every timeout in the chain to 20 seconds would expose the whole path to the slow case.
Does the downstream stop working when the caller times out?
Not by itself. Over HTTP/1.1 the server may notice the closed connection only when it tries to write. That is why deadline propagation matters: it lets each hop stop proactively. Reactive stacks can also cancel the in-flight downstream call when the upstream subscription is cancelled.
Should retries count against the same budget?
Yes. Every attempt and every backoff wait comes out of the caller's budget. If we retry, each attempt's timeout has to be smaller, so the total still fits. Retrying with the full timeout each time is a common way to exceed the caller's deadline.
7Conclusion
In this answer, we saw that an inner timeout longer than the caller's wastes threads, connections and dependency capacity on responses nobody will read, and under load turns a slow dependency into an outage. Timeouts should shrink along the chain, with each hop's attempts and backoff fitting inside its caller's budget. Propagating a deadline, such as a remaining-time header, lets each service stop early when the budget is spent, and the values themselves should come from measured latency percentiles rather than round numbers.
Open with
The problem is that the inner timeout outlives the outer one. Our caller gives up after 5 seconds, but we keep waiting on the dependency for up to 10, so whenever the dependency is slow we hold a thread, a pooled connection and maybe a transaction for work whose answer nobody will receive.
Then, if they want more
At 100 requests per second, 3 wasted seconds per request is 300 busy threads, which is more than a default Tomcat pool, so a slow dependency becomes an outage of our whole service, and user retries make it worse. Timeouts should shrink along the chain.
I treat the caller's 5 seconds as a budget: subtract our own work and a margin, and what is left has to cover every attempt to the dependency plus backoff. With one retry that might leave about 2 seconds per attempt as a ceiling.
Better is to propagate a deadline, for example a header with the remaining milliseconds, so each service subtracts what it used, refuses to start a call if nothing is left, and passes the smaller budget on.
And within that ceiling I would choose the actual timeout from the dependency's measured percentiles, a bit above p99, rather than a round number like 10 seconds.
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 Framework reference, Spring Web MVC
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 calls a dependency with a 10 second read timeout, and its own callers use a 5...": https://scrivio-interview-library.netlify.app/spring-boot/http-clients/5528a9466a/