RETRIES, BACKOFF & JITTER

Retrying immediately turns one failure into a flood

L215 MINRELIABILITY
PREDICT

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.

▶ SIMULATION
CLIENTS (8)
policy: immediate retry
waiting 0 · served 0 · gave up 0
next sends: —
DEPENDENCY
status: RESTARTING (503 until t=5)
capacity: 4 / tick
load this tick: 0
CLOCK
t = 0 ticks (0 ms)
sent 0 · peak 0 / tick
waiting for the restart
✓ requests per tick never exceed capacity (4)
SCHEDULE
01[CLIENTS]clients: retry on the very next tick
02[DEP]dependency restarts: every in-flight request fails at t = 0
03[CLOCK]clock: advance to the next tick with a send
04[CLOCK]clock: advance to the next tick with a send
05[CLOCK]clock: advance to the next tick with a send
06[CLOCK]clock: advance to the next tick with a send
07[CLOCK]clock: advance to the next tick with a send
08[CLOCK]clock: advance to the next tick with a send
09[CLOCK]clock: advance to the next tick with a send
10[CLOCK]clock: advance to the next tick with a send
11[CLOCK]clock: advance to the next tick with a send
12[CLOCK]clock: advance to the next tick with a send
13[CLOCK]clock: advance to the next tick with a send
14[CLOCK]clock: advance to the next tick with a send
15[CLOCK]clock: advance to the next tick with a send
16[CLOCK]clock: advance to the next tick with a send
17[CLOCK]report
Start of immediate retry scenario. 17 steps.
// 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
}

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.

BREAK IT NOT YET

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

FIX IT NOT YET

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.

Mental model:

a failure that hits many clients at once synchronizes them, and synchronized clients retry as one wave. Backoff decides when the wave lands; jitter decides how wide it is. You need both, plus a cap on attempts and a deadline that stops retries the moment nobody is waiting for the answer any more.

IN PRODUCTION

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.

IN INTERVIEWS

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

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: RETRY STORMS →