RETRY STORMS
Every layer retries, and 3 becomes 27
Edge, api and db driver each make up to 3 attempts. The db is slow enough that every query times out at 1 s. One user request arrives. How many db queries run, and how long until the user sees an error?
Retries that look reasonable at each layer compound across layers. The edge proxy retries a failed api call three times. Each api call retries its data access three times. Each data access lets the db driver try the query three times. One user request whose query cannot succeed costs 3 × 3 × 3 = 27 queries, all in sequence, each paying the full timeout, before the user sees an error.
That is a retry storm: a slow dependency receives many times its normal load at exactly the moment it can least afford it, from callers who each believe they are being careful. The fix is to retry in one place and make every other layer propagate the error, and to cap retries with a budget so a sustained failure cannot multiply at all.
// edge proxy: retries = 3
// api handler: for (let i = 0; i < 3; i++) try { return await dal.get(id); } catch {}
// db driver: maxRetries: 3
// one slow query -> 3 * 3 * 3 = 27 queries, 27 s, one error// retry in ONE place, with a budget:
// edge proxy: retries = 0
// api handler: no loop; propagate the error
// db driver: maxRetries: 3, only if retryBudget.allow()
// retryBudget: retries <= 10% of requests (the Google SRE book figure),
// plus a small floor of retries per second so a quiet client
// can still retry (Finagle defaults: 20%, plus 10 retries/s) Watch the amplification row and the invariant strip. In RETRY STORM the factor passes 3 on the fourth query and ends at 27 with the user still waiting. In RETRY AT ONE LAYER the same slow db costs 3 queries and the user gets an error in 3 s.
Three healthy requests, every layer retrying 3 times. Inject one db fault and find a position where the amplification factor blows past 3. Try both faults.
GOAL: amplification > 3 (db queries per user request)
Implement a retry budget: a retry is allowed only while granted retries stay at or under 10% of requests seen so far (budget.ratio). Never exceed the cap, and never deny a retry while there is room. The grader drives three request streams and counts.
A load balancer with retries 3, an HTTP client with a default retry policy, a service mesh sidecar that retries on 5xx, a database driver with maxRetries, all stacked in one request path and each unaware of the others. The symptom is a dependency whose load climbs as its health falls.
“Our db gets slow and the whole site goes down. Where would you look first?” Count the retrying layers and multiply. Then propose one retry layer, a retry budget, and a deadline shared down the chain, and explain why bumping a timeout somewhere would make it worse.
USED IN
Chapters that build on this lesson.
- On-call and incidents for managersEngineering Manager
- Technical decisions as a managerEngineering Manager
- When a bank or a switch goes downPayments
- Chaos and resilience testingSRE, Platform and DevOps
- Leading a sev-1 as the technical leadStaff and Principal Engineer