Retry with backoff
Automatically try a failed call again after a growing, randomised delay, because many cloud failures are brief and fix themselves.
Description
In the cloud, many failures are transient: a dropped connection, a throttled request, a database failing over, a pod restarting. Trying again a moment later often just works. A retry policy does this automatically: it catches retryable errors, waits, and tries again a limited number of times.
The waits grow exponentially (0.2 s, 0.4 s, 0.8 s…) so a struggling service gets breathing room, and each wait gets random jitter so thousands of clients don't retry in lockstep. Retries are only safe when the operation is idempotent: doing it twice must have the same effect as once.
System design
Retry with backoff system design diagram
- Checkout app (client).
- Order service (service).
- Retry policy (gateway): 3 tries · backoff + jitter.
- Inventory API (external service).
- Step 1: Checkout app → Order service: place order.
- Step 2: Order service → Retry policy: reserve(stock, key).
- Step 3: Retry policy → Inventory API: attempt.
- Step 4: Inventory API → Retry policy: 503 (transient) (failure path).
- Step 5: Retry policy → Order service: OK, or give up.
- The checkout app places an order.
- The order service reserves stock through its retry policy, sending an idempotency key with the request.
- The policy makes the first attempt against the inventory API.
- A transient error (timeout, 503) comes back. The policy waits about 0.2 s plus random jitter and tries again, then about 0.6 s, at most 3 attempts.
- The service gets the successful answer, or a clear failure after the last attempt, never an endless wait. The idempotency key stops a slow first attempt and a retry from reserving twice.
- AWS
- AWS SDKs retry with exponential backoff and jitter by default (adaptive retry mode); Step Functions has retry policies per state.
- Azure
- Azure SDK retry policies; Polly in .NET; Durable Functions retry options.
- Google Cloud
- Google Cloud client libraries retry idempotent calls; Cloud Tasks and Workflows have retry settings.
When to use it
Use it when
- Calls to remote services, databases or queues that fail now and then for short periods.
- Errors are clearly transient: timeouts, connection resets, HTTP 429/502/503/504.
- The operation is idempotent, or you can make it so with an idempotency key.
Avoid it when
- The error is permanent: validation failures, 400, 401, 403, 404. Retrying wastes time and load.
- The dependency is down for a long time. Retries pile on; let a circuit breaker stop them.
- The user is waiting and the total retry time would exceed their patience. Fail fast and retry in the background.
Pitfalls
- Retry storms: every layer retries (client, gateway, service), so one failure multiplies into dozens of calls. Retry at one layer only.
- Retrying non-idempotent operations, such as charging a card twice. Send an idempotency key the server deduplicates on.
- No jitter, so clients synchronise and hit the recovering service in waves.
- Unbounded retries or total time. Cap attempts and set an overall deadline.
Alternatives
Circuit Breaker
Choose it when the dependency is down rather than flaky. Usually combined: retry briefly, and let the breaker stop retrying during an outage.
Queue-Based Load Leveling
Choose it when the work can wait. A queue with redelivery retries for you, outside the user's request.
Hedged requests
Choose it when latency matters more than load: send a second request if the first is slow, and use whichever answers first.