Designbench

Lesson 5.1 · 20 min

Timeouts, retries and idempotency

Place a timeout on a real latency tail, watch retries keep a server down after the incident ends, then make a retried payment charge only once.

The idea in plain words

If a phone call drops, you wait a moment and call back. Software does the same, but if everyone calls back at once the line stays jammed, and if the first call actually went through you may have ordered twice.

The problem it solves

Calls between services fail for brief reasons: a dropped packet, a restart, a moment of overload. Waiting forever freezes your service; giving up at once fails requests that would have worked; retrying carelessly makes outages worse or repeats actions.

How it works

  1. Set a timeout so a slow call can’t hold your resources forever.
  2. Retry only errors that may succeed next time (timeouts, 503s), never “bad request”.
  3. Wait longer between attempts (backoff) and add randomness (jitter) so clients don’t retry in sync.
  4. Cap the number of retries so an outage isn’t multiplied.
  5. Make retried writes idempotent with a request key, so doing them twice has no extra effect.

Example

A payment call times out. Did it go through? If you retry without a key you might charge twice. With an idempotency key, the second attempt is recognised and returns the first result: one charge, whatever happened.

Key terms

Timeout
How long you wait for an answer before giving up.
Retry
Trying a failed call again.
Exponential backoff
Waiting longer after each failure: 100 ms, 200 ms, 400 ms…
Jitter
Adding randomness to the wait so clients don’t all retry at the same instant.
Idempotency key
A unique id sent with a request so the server can recognize and ignore a repeat.

In this lesson you'll learn

Sections

  1. Theory: choose a timeout
  2. Theory: retry storms
  3. Theory: idempotency keys
  4. Design: safe to retry?
  5. Check yourself

Cheat sheet

Timeoutabove dependency p99, inside your deadline
Retrytransient errors only, a few times
Backoffexponential + full jitter + budget
Layersattempts multiply: retry at one layer
Retried POSTneeds an idempotency key

The interactive simulations and the quiz load with JavaScript.