RETRY STORMS

Every layer retries, and 3 becomes 27

L214 MINRELIABILITY
PREDICT

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.

▶ SIMULATION
EDGE
attempt — of 3
retries up to 2×
API
attempt — of 3
retries up to 2×
DB DRIVER
attempt — of 3
retries up to 2×
DB
status: fast (20 ms)
queries: 0 for 0 user requests
this request: — queries
clockt = 0.0 s
amplification×— (0 db queries / 0 requests)
requests0 served · 0 failed
last event—
✓ amplification (db queries per user request) ≤ 3
SCHEDULE
01[SVC]config: edge, api and driver each make up to 3 attempts
02[DB]db becomes slow: every query times out after 1 s
03[EDGE]user request #1 arrives at the edge
04[DRIVER]edge 1/3 · api 1/3 · driver 1/3 → query db
05[DRIVER]edge 1/3 · api 1/3 · driver 2/3 → query db
06[DRIVER]edge 1/3 · api 1/3 · driver 3/3 → query db
07[DRIVER]edge 1/3 · api 2/3 · driver 1/3 → query db
08[DRIVER]edge 1/3 · api 2/3 · driver 2/3 → query db
09[DRIVER]edge 1/3 · api 2/3 · driver 3/3 → query db
10[DRIVER]edge 1/3 · api 3/3 · driver 1/3 → query db
11[DRIVER]edge 1/3 · api 3/3 · driver 2/3 → query db
12[DRIVER]edge 1/3 · api 3/3 · driver 3/3 → query db
13[DRIVER]edge 2/3 · api 1/3 · driver 1/3 → query db
14[DRIVER]edge 2/3 · api 1/3 · driver 2/3 → query db
15[DRIVER]edge 2/3 · api 1/3 · driver 3/3 → query db
16[DRIVER]edge 2/3 · api 2/3 · driver 1/3 → query db
17[DRIVER]edge 2/3 · api 2/3 · driver 2/3 → query db
18[DRIVER]edge 2/3 · api 2/3 · driver 3/3 → query db
19[DRIVER]edge 2/3 · api 3/3 · driver 1/3 → query db
20[DRIVER]edge 2/3 · api 3/3 · driver 2/3 → query db
21[DRIVER]edge 2/3 · api 3/3 · driver 3/3 → query db
22[DRIVER]edge 3/3 · api 1/3 · driver 1/3 → query db
23[DRIVER]edge 3/3 · api 1/3 · driver 2/3 → query db
24[DRIVER]edge 3/3 · api 1/3 · driver 3/3 → query db
25[DRIVER]edge 3/3 · api 2/3 · driver 1/3 → query db
26[DRIVER]edge 3/3 · api 2/3 · driver 2/3 → query db
27[DRIVER]edge 3/3 · api 2/3 · driver 3/3 → query db
28[DRIVER]edge 3/3 · api 3/3 · driver 1/3 → query db
29[DRIVER]edge 3/3 · api 3/3 · driver 2/3 → query db
30[DRIVER]edge 3/3 · api 3/3 · driver 3/3 → query db
31[DB]report
Start of retry storm (3 × 3 × 3) scenario. 31 steps.
// 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

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.

INJECT A FAULT NOT YET

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)

FIX IT NOT YET

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.

Mental model:

retries multiply across layers, so the number that matters is the product of every layer’s attempts, not any one layer’s count. Put retries in one layer and make the rest propagate errors, and cap them with a budget tied to the request rate, so retries can help a blip but can never amplify an outage.

IN PRODUCTION

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.

IN INTERVIEWS

“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.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.

USED IN

Chapters that build on this lesson.

NEXT: CIRCUIT BREAKERS →