Resilience · Pattern
Timeouts
Give every remote call a maximum wait, so a hung dependency cannot hold your threads, memory and connections forever.
In one Amazon system, calls to a dependency had a timeout of “around 20 milliseconds”, and a small number of them timed out right after deployments. Marc Brooker, who worked on it, found why:
“Digging in, I found that the timer included establishing a new secure connection, which was reused on subsequent requests.”Marc Brooker, Amazon Builders’ Library
A new server’s first call had to open that connection, and opening it took longer than 20 ms. Later calls reused it. One timer was covering two jobs, connecting and the request. The fix: open the connections at startup, before taking traffic.
Give every remote call a maximum wait, so a hung dependency cannot hold your resources forever.
What it is
“Timeouts are the maximum amount of time that a client waits for a request to complete.”Marc Brooker, Amazon Builders’ Library
Simple to state, and not always on by default. Python’s Requests:
“By default, requests do not time out unless a timeout value is set explicitly. Without a timeout, your code may hang for minutes or more.”Requests documentation
The problem
A call that never returns is not idle. It holds what it was using: memory, threads, connections, ports, “or anything else that is limited” (Amazon). The Google SRE book shows how that becomes an outage, in a worked example rather than a measured incident, assuming no other secondary effects:
- A frontend of 10 servers with 100 threads each has 10 × 100 = 1,000 threads. It serves 1,000 queries per second (QPS), each in 100 ms.
- Then 5% of requests stop completing and wait out a 100-second deadline, the book’s word for a timeout: 5% × 1,000 = 50 QPS, each holding a thread for 100 s, or 50 × 100 = 5,000 threads.
- The other 95% still need 950 QPS × 0.1 s = 95 threads.
- That is 5,095 threads’ worth of work for 1,000 threads: the frontend handles only 1,000 ÷ 5,095 = 19.6%, an 80.4% error rate.
The book puts it down to the deadline:
“In the preceding example, a small number of requests initially hit the deadline, but the deadline was three orders of magnitude larger than the normal mean latency, leading to thread exhaustion.”Google SRE book
From first principles
- What does a timeout protect? The thread, connection or port a call holds while it waits.
- Why not set it high? Amazon: “Setting a timeout too high reduces its usefulness, because resources are still consumed while the client waits for the timeout.”
- Why not set it low? Calls that would have succeeded fail, and are often retried. Amazon: “Increased small backend latency leading to a complete outage, because all requests start being retried.”
- So where does the number come from? From the dependency’s measured latency. Within an AWS Region, Amazon first picks “an acceptable rate of false timeouts (such as 0.1%)”: calls cut off that would have succeeded. The timeout is then the matching percentile, p99.9: the time 99.9% of calls finish within.
- When does that fail? When clients have substantial network latency, such as over the internet. Amazon then factors in “reasonable worst-case network latency”. It also fails where p99.9 is close to p50, the median: there Amazon adds “some padding”, so a small rise in latency does not cause many timeouts.
- Why not only a fresh timeout at every hop? A server further down can then think it has time to spare, and keep working after the original caller has given up. Pass down what is left as well.
In the SRE book’s numbers:
time left = deadline - time spent A: 30 s, works 7 s → B gets 23 s B: works 4 s → C gets 19 s
The book adds that you may want to trim each outgoing deadline “a bit (e.g., a few hundred milliseconds)” for network transit, and to “consider setting an upper bound for outgoing deadlines”. A call then stops at whichever comes first: its own limit or the time left.
The solution
- Put one on every remote call, connection and request both. Amazon: “In general, we prefer to use the timeouts built into well-tested clients.”
- Propagate the deadline from the top of the stack, so every call in the tree shares one absolute deadline (Google SRE book).
- Check what is left before doing more work. The SRE book: the server should check “the deadline left at each stage before attempting to perform any more work on the request.”
- Keep it in proportion to normal latency. “Having deadlines several orders of magnitude longer than the mean request latency is usually bad.” (Google SRE book)
Patterns: connect, read and total are different timers
“Timeout” means a different span in each of these. Defaults as documented on 19 October 2026:
| Software | Setting | Default | What it actually covers |
|---|---|---|---|
| nginx | proxy_connect_timeout | 60 s | establishing the connection only |
| nginx | proxy_read_timeout | 60 s | the gap between two reads, not the whole response |
| Envoy | route timeout | 15 s | end of the request to end of the response, all retries included |
| gRPC | deadline | none | the whole call |
| Go net/http | Client.Timeout | 0, meaning none | connection, redirects and reading the body |
Do
- Set one on every remote call, connection and request both (Amazon).
- Within a Region, derive the value from the dependency’s latency percentile (Amazon).
- Propagate one deadline down the call tree, and check what is left (Google SRE book).
Don’t
- Leave a remote call with no timeout (Requests: “your code may hang for minutes or more”).
- Set one several orders of magnitude above mean latency (Google SRE book: “usually bad”).
- Treat a read timeout as a total timeout (nginx: it is set “only between two successive read operations”).
Trade-off
Set it too long, and callers keep holding resources while a dependency below them has problems: the 100-second deadline above tied up 5,000 threads. Set it too short, and some more expensive, slower requests can fail every time. The Google SRE book:
“Balancing these constraints to pick a good deadline can be something of an art.”Google SRE book
A timeout also cannot tell you whether the work ran: the server may finish just after you give up. So retry a call with side effects only if it is idempotent, for example through an idempotency key.
How it fits with the rest
A timeout turns an unbounded wait into a failure you can act on. Backoff with jitter decides when to retry after it fires, and if several layers each retry, the attempts can multiply into a retry storm. When timeouts are missing or far too long, a slow dependency can pull its callers into a cascading failure.
Practise it in two minutes
Predict what happens, watch it move, change the numbers, and get tested again before you forget.
Open Timeouts in the app →Related
Sources
- Marc Brooker, “Timeouts, retries, and backoff with jitter”, Amazon Builders’ Library
- Google SRE book, “Addressing Cascading Failures”
- gRPC documentation, “Deadlines” guide
- Envoy API documentation, config.route.v3.RouteAction
- nginx, ngx_http_proxy_module
- Requests documentation, Advanced Usage
- Go net/http, Client.Timeout