System DesignIntermediate13 min

Idempotency, retries & timeouts

Make repeating an operation safe, and retry in a way that heals failures instead of amplifying them.

See it on the map

Networks fail in the gap between doing the work and confirming it. A client that retries a payment request cannot know whether the first attempt went through. The fix is an idempotency key: the client sends a unique key per logical operation, and the server returns the stored result for a key it has already processed.

Retries need discipline. Use exponential backoff with jitter so thousands of clients do not retry in lockstep, cap the attempts, and only retry errors that can succeed later. A retry storm against an already struggling service turns a blip into an outage.

Every call needs a timeout, and timeouts should shrink as you go down the call chain so the caller gives up before its caller does. Circuit breakers stop sending traffic to a dependency that is clearly down.

Key points

  • Idempotency keys make retries safe for non-idempotent operations.
  • Backoff with jitter, a retry cap, and retry only retryable errors.
  • No call without a timeout. Deadlines propagate down the chain.
  • Circuit breakers protect both your service and the dependency.

Answer these out loud

  1. 1Design the storage for idempotency keys. How long do you keep them and what happens on a concurrent duplicate?
  2. 2Why does a retry at every layer of a four-tier system multiply load, and how do you stop it?

Build it

Build a tiny HTTP handler that accepts an Idempotency-Key header and returns the same response for repeated keys, even under concurrent requests.

Use this from an agent

Any MCP client, including Grok, can read this lesson. See how to connect.

REST
curl https://engineeros-delta.vercel.app/api/v1/topics/idempotency-and-retries

This unlocks