Course contents

09. Reliability and Resilience Lesson 3 of 10

Exponential Backoff and Jitter

Watch fixed-delay retries hit a restarting API in synchronised pulses, then see exponential backoff stretch them out and full jitter spread them apart.

11 minIntermediate6 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • Restarts, deploys and network blips fail many clients at the same instant.
  • With fixed delays, those clients retry together, in pulses, and short delays give up before the outage ends.
  • Exponential backoff waits longer each time: less pressure on a dead service, and the retries span the outage.
  • Without jitter the clients stay synchronised; full jitter (random 0…backoff) spreads them evenly.
  • delay = random(0, min(cap, base × 2^attempt)), with an attempt limit and an overall deadline.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

Backoff is the waiting time between retry attempts. With exponential backoff the wait grows by a constant factor (usually doubling) after every failure, up to a cap. Jitter adds randomness to each wait so that clients that failed at the same moment do not retry at the same moment. Together they are the standard way to schedule retries, reconnects and polling loops.

Why it exists

Failures are often correlated: a server restarts and drops every connection at once, a deploy cycles a fleet, a network partition heals. Thousands of clients then experience the failure within the same millisecond. If each of them retries after the same fixed delay, they arrive together again, as a pulse, and a pulse can be large enough to knock the recovering service over, which produces the next synchronised failure. Short fixed delays have a second problem: they burn through all attempts in a fraction of a second, long before a typical outage is over, while keeping the dead service busy rejecting requests.

How it works

Exponential backoff. The wait before retry n is base × 2^(n−1), truncated at a maximum: 100 ms, 200 ms, 400 ms, 800 ms … up to, say, 10 s. Each failure halves the rate at which a client knocks, so a service that is down sees the retry pressure fade instead of staying constant, and a client’s attempts cover a longer stretch of time, long enough to outlast a short outage.

Jitter. Exponential backoff alone keeps synchronised clients synchronised: everyone who failed at time t retries at t + 100 ms, t + 300 ms, t + 700 ms, together. Jitter randomises each wait:

  • Full jitter: delay = random(0, backoff). Spreads clients uniformly over the whole interval; the expected wait is half the backoff.
  • Equal jitter: delay = backoff / 2 + random(0, backoff / 2). Guarantees some minimum wait, spreads a little less.
  • Decorrelated jitter: delay = min(cap, random(base, previous × 3)). Each wait depends on the previous one rather than on the attempt number.

AWS’s published analysis of these variants found full and decorrelated jitter clearly better than no jitter for contended workloads, and full jitter is the variant many client SDKs implement.

Limits. A cap on the single wait (without one, the tenth wait from 200 ms would be about 100 s), a maximum number of attempts, and an overall deadline that the whole retry sequence must fit into. When the limits are reached the call fails, ideally into a fallback, and a circuit breaker can take over.

Server hints. If the server sends Retry-After (with 429 or 503), use it as the minimum wait, still with jitter added, so many clients do not all return at the advertised second.

When to use it

  • Every automatic retry of a remote call.
  • Reconnect loops: WebSocket, database, message-broker and cache clients after a disconnect.
  • Polling: job status, leader election, lock acquisition.
  • Scheduled jobs on many machines: add a random offset so a fleet does not run "every minute at :00" in unison.

When not to

  • As the only protection against overload: backoff spreads retries, it does not reduce how many are sent. Add a retry budget or a circuit breaker.
  • For interactive actions where the user is waiting and the remaining deadline is shorter than the next backoff; fail and show the error instead.
  • With a very large cap on interactive paths: a 60 s wait is fine for a background sync, not for a checkout button.

Trade-offs

Choice You gain You pay
Fixed delay Simple, predictable Synchronised pulses; gives up quickly or keeps knocking at the same rate
Exponential, no jitter Falling pressure, covers longer outages Correlated clients stay in lockstep
Full jitter Best spread, simple Some retries happen almost immediately; average wait is shorter, so attempts end sooner
Equal jitter A guaranteed minimum wait Less spread than full jitter
Higher cap Survives longer outages Longer worst-case waits for the user
More attempts More chances to succeed More load during incidents; longer before a clear failure

Alternatives

  • Retry budgets limit the number of retries rather than their timing.
  • Circuit breakers stop retrying entirely while a dependency is failing.
  • Server-driven backoff: Retry-After, or a gateway that sheds load with explicit retry advice.
  • Queue-based retries: put failed work on a delay queue so the timing is controlled centrally.
  • Token-bucket rate limits on the client cap the request rate during reconnect storms.

Failure modes

  • Thundering herd on recovery: a fleet of clients without jitter reconnects in one pulse the moment a service comes back.
  • No cap: waits grow to minutes or hours; clients look hung.
  • Jitter too small (±10%): clients stay clustered.
  • Backoff per thread, not per client: many threads in one process each back off independently and still flood the service.
  • Backoff reset on every success at low traffic: a single lucky call resets the delay and the client immediately returns to aggressive retrying.
  • Retry backlog after a long outage: pending retries plus new traffic arrive together at the recovered service; the lesson’s last step shows a mild version.

In production

Use the retry helpers of your SDK or resilience library (AWS SDKs, Google client libraries, gRPC retry policies, Polly, Resilience4j, Envoy) and check that jitter is enabled; some libraries default to none. Typical values for synchronous calls: base 50–200 ms, cap 1–10 s, 2–4 attempts, inside an overall deadline. For background reconnects: base 1 s, cap 30–60 s, unlimited attempts with jitter. Honour Retry-After. Watch for pulses in request-rate graphs with sub-second resolution after deploys and restarts; a sawtooth is the signature of missing jitter.

Common misconceptions

  • "Exponential backoff prevents thundering herds." Without jitter it only spaces the herd’s visits further apart.
  • "Jitter makes retries slower." Full jitter makes the average wait shorter than plain exponential backoff; it makes the arrivals more even.
  • "Backoff reduces the number of retries." With an attempt limit, every retry is still eventually sent; backoff changes when.
  • "A small random offset is enough." The spread has to be comparable to the backoff itself to break the synchronisation.

Interview angle

Whenever you say "and the client retries", add "with exponential backoff and jitter, capped, within a deadline". Be ready to explain why jitter matters with the restart example, to write the formula random(0, min(cap, base × 2^attempt)), and to say that backoff spreads load while budgets and breakers limit it. Mentioning reconnect storms (WebSocket or cache clients after a failover) shows you have seen the problem outside of HTTP retries.

Model assumptions

The simulation is a simplified model, not a benchmark. Clients send 60 requests per second (Poisson) to an API with 8 workers, an 80 ms mean service time (lognormal, cv 0.3) and room for 40 waiting requests; each hop takes 30 ms. Every step replays the same incident: the API is 3× slower from 0 s, so its queue fills; at 1.5 s it goes down, failing everything inside it at the same instant; it is back, healthy, at 3 s (at 7.5 s in the last incident step). Retries use the engine’s retry policy: up to 6 attempts, a base delay of 200 ms that doubles up to a 1.6 s cap (or a fixed 200 ms), with no jitter or full jitter; a retry starts when the client hears of the failure. There are no client timeouts. Numbers show behaviour and orders of magnitude only.

The lesson as textEvery step of the simulation, written out.
  1. 1. Many requests fail at the same instant

    Mobile clients send 60 requests a second to an Orders API that can handle about 100. Then it starts struggling: from 0 s it is 3× slower, and its queue of 40 waiting requests fills up.

    At 1.5 s the orchestrator restarts it. Every request inside (8 in progress, 40 waiting) fails at the same instant. For 1.5 s the API is down and refuses every new request; at 3 s it is back and healthy.

    There are no retries yet, so all of those requests are simply lost. Remember the crowd of failures at 1.5 s: it is what the next steps are about.

    Scene: The API slows down and its queue fills. At 1.5 seconds it restarts and everything inside it fails at the same moment; it is down until 3 seconds. Without retries those requests are lost.

    Key idea: Correlated failures (a restart, a network blip, a deploy) hit many clients at the same moment. What the clients do next decides how recovery goes.

  2. 2. Fixed delays retry in lockstep

    The clients now retry up to 5 times (6 attempts in total), each retry exactly 200 ms after hearing of the previous failure.

    Watch the connection at 1.5 s. The crowd that failed together retries together: a pulse of about 48 requests leaves in the same millisecond, finds the API still down, fails together, and comes back as the same pulse 200 ms after hearing so (260 ms with the round trip). Each pulse is dozens of requests at once, where normally one arrives every 17 ms or so.

    And they give up too early: five retries 260 ms apart are over after about 1.3 s, but the outage lasts 1.5 s. The crowd burns all its attempts against a dead server and fails anyway, while retries from everyone else knock on the dead server several times as often as new requests arrive.

    Scene: With fixed 200 ms retries, the requests that failed together at the restart retry together in pulses every 200 ms, all fail against the down server and run out of attempts before it returns.

    Key idea: Fixed retry delays keep a crowd of failed clients synchronised, and short fixed delays give up before a real outage is over.

  3. 3. Exponential backoff: wait longer each time

    Now each wait doubles: 200 ms, 400 ms, 800 ms, then 1.6 s (the cap) and 1.6 s again. The retries can now span almost 5 s instead of 1.3 s, which outlasts the 1.5 s outage, so most of the crowd succeeds on a later attempt. While the API is down, clients also knock far less often.

    But look at the connection again: the crowd still moves in lockstep. Everyone who failed at 1.5 s retries at about 1.7 s, 2.2 s and 3.1 s, as one pulse each time; the third pulse lands just after the API is back, all at once. Backoff spread the attempts out in time; it did not spread the clients out from each other.

    Scene: With exponential backoff the retries spread over almost 5 seconds and most succeed after the restart, but the clients that failed together still retry together in pulses.

    Key idea: Exponential backoff gives a struggling service progressively more room and lets retries outlast an outage. On its own it keeps synchronised clients synchronised.

  4. 4. Full jitter breaks the lockstep

    Last change: full jitter. Each client waits a random time between 0 and the backoff (0–200 ms, then 0–400 ms, 0–800 ms, 0–1.6 s, 0–1.6 s) instead of exactly the backoff.

    The pulses are gone. The crowd’s retries now trickle in at a few per moment instead of dozens at once, so the API sees close to its normal arrival rate even right after the restart. Clients still back off exponentially, so the load on a dead server still drops; they just no longer move as one.

    Randomness is the cheapest coordination there is: no client needs to know about any other.

    Scene: With exponential backoff and full jitter, the retries of the clients that failed together are spread randomly over time; there are no pulses and the API sees an even stream.

    Key idea: Add jitter to every retry delay. Full jitter (random between 0 and the backoff) spreads a synchronised crowd evenly over time.

  5. 5. Cap the wait, cap the attempts

    This time the outage lasts 6 seconds. With 6 attempts and a 1.6 s cap, a client’s retries cover at most about 5 s, and about half that on average with jitter, so many requests eventually fail cleanly instead of waiting forever. When the API returns at 7.5 s, it first meets a backlog (pending retries on top of new requests, more than it can serve for a moment); a few seconds later everything succeeds again.

    That is deliberate. The cap stops one wait from growing to minutes (without it, the tenth wait would be 200 ms × 2⁹ ≈ 100 s). The attempt limit and an overall deadline bound how long a user waits for an answer. A failure after a few seconds is better than a spinner that never ends, and it stops clients piling onto a service that is clearly not coming back soon; that is the moment for a circuit breaker.

    Scene: The API is down for 6 seconds. Clients retry with capped, jittered backoff, run out of attempts and fail cleanly instead of waiting indefinitely; when the API returns it works through a backlog of retries, then requests succeed again.

    Key idea: Backoff needs limits: a maximum delay, a maximum number of attempts and an overall deadline. Long outages should end in a clear failure.

  6. 6. Backoff with jitter, within limits

    The API is healthy and the clients keep the policy: up to 6 attempts, exponential backoff from 200 ms capped at 1.6 s, full jitter.

    The recipe: delay = random(0, min(cap, base × 2^attempt)). Use it for every retry loop, reconnect loop and polling loop, in clients and servers alike. Combine it with a retry budget and a circuit breaker so that backoff never becomes the only thing standing between a struggling service and its callers.

    Scene: A healthy API with clients using exponential backoff and full jitter: every request succeeds without retries.

    Key idea: delay = random(0, min(cap, base × 2^attempt)): exponential so the pressure drops, jitter so clients spread out, a cap so waits stay bounded.