RETRIES, BACKOFF & JITTER
Retrying immediately turns one failure into a flood
8 clients fail at the same instant. Each retries with exponential backoff and no randomness: it waits base · 2^attempt, so every wait doubles. The dependency can serve 4 requests per tick. How big is the second retry wave?
A retry is a second request. When one client’s request fails, retrying is cheap and usually right. When every client’s request fails at the same moment, because the dependency restarted or a network path flapped, every client retries at the same moment, and the dependency sees the whole load again, on top of whatever is still queued.
Exponential backoff makes each client wait longer between attempts: base · 2^attempt, up to a cap. That spaces the waves out in time, but the clients that failed together still wait the same time and retry together. Jitter breaks the synchronization: each client waits a random amount between 0 and its backoff, so one wave spreads across the whole window.
// retry loop in every client: first try + 5 retries
for (let attempt = 0; attempt < 6; attempt++) {
const res = await fetch(url);
if (res.ok) return res;
// no wait: try again right now
}// exponential backoff with full jitter: first try + 5 retries
const MAX_ATTEMPTS = 6;
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
const res = await fetch(url);
if (res.ok) return res;
if (attempt === MAX_ATTEMPTS - 1) break; // no sleep after the last try
const ceiling = Math.min(cap, base * 2 ** attempt);
await sleep(Math.random() * ceiling); // random(0, ceiling)
} Watch the invariant strip and the per-tick bars. IMMEDIATE floods every tick and burns the clients’ retry allowance: by the tick the dependency comes up, half of them have given up. BACKOFF moves the 8-wide wave to t=4 and t=12 and is still red. JITTER keeps every tick at or under 4 with the same 8 clients and the same restart.
That is the likely outcome, not a promise. Jitter makes the average load per tick the client count divided by the backoff window, so a tick over capacity becomes unlikely, not impossible. The window also has to be wide enough to hold everyone. Slide CLIENTS to 16 and JITTER goes red too: 16 clients do not fit at 4 per tick in that window.
Exponential backoff, no jitter. The dependency serves 4 requests per tick. Slide CLIENTS until you find the smallest client count that overloads it.
GOAL: peak load exceeds capacity, and one client fewer would not
Implement exponential backoff with full jitter: the delay before retry number attempt (0-based) is a uniformly random value in [0, min(cap, base · 2^attempt)]. Use rng() for randomness, never Math.random, so the grader can replay you.
SDK defaults (most cloud SDKs ship backoff with jitter; most hand-written for loops do not), message consumers that redeliver on failure, cron jobs that all start at :00, mobile apps that reconnect when the push server restarts. The symptom is a dependency whose recovery takes far longer than its restart.
“Design a retry policy for this client.” Say: bounded attempts, exponential backoff with full jitter, a deadline budget that overrides both, and retry only on errors that can succeed on a second try (timeouts, 503, 429; never 400). Then volunteer that retries across several layers multiply, which is the next lesson.
USED IN
Chapters that build on this lesson.
- Architecture governance and platform investmentHead of Engineering
- Debited but not credited: timeouts, status queries and reversals between banksPayments
- Idempotency and moving money exactly oncePayments
- Project: a wallet with funding, transfers, refunds and daily reconciliationPayments
- Routing across providers to raise success ratesPayments
- Running a switch: uptime, success rates per bank and connecting to other switchesPayments
- When a bank or a switch goes downPayments
- When the money is wrong: payments incidentsPayments
- Platform, API and technical PMProduct Manager
- API, contract and integration testingQA and Quality Engineering
- Mobile and accessibility testingQA and Quality Engineering
- Test strategy and test plansQA and Quality Engineering
- Testing philosophies: pyramid, trophy, exploratory, risk-basedQA and Quality Engineering
- Code review, giving and receivingSoftware Engineer
- Engineering philosophies: simple first, ship small, own what you runSoftware Engineer
- Technical debt and the trade-offs you defendSoftware Engineer
- AI in operations: agents on call and what they may touchSRE, Platform and DevOps
- Chaos and resilience testingSRE, Platform and DevOps
- Production readiness reviewsSRE, Platform and DevOps
- Architecture reviews and governanceStaff and Principal Engineer