Preventing Cascading Slowdowns with Timeouts, Retries and Backoff
This lesson explains how correct timeouts and disciplined retries prevent the slowdowns that spread through distributed systems, and how to recognise designs that lack them.
Learning outcomes
After completing this lesson, you will be able to:
- Explain why timeouts must be shorter than the caller's deadline.
- Explain retries with exponential backoff and jitter.
- Identify the retries that AWS services perform.
Timeouts
Every remote call needs a timeout shorter than the caller's own deadline. Without one, a slow dependency holds threads and connections until the caller runs out of them. Set timeouts from measured latency (for example slightly above p99.9), and make sure layered timeouts shrink inwards: an API Gateway integration timeout must exceed the Lambda function's work, and an SQS visibility timeout must exceed the consumer's processing time, or messages are processed twice.
Retries with exponential backoff and jitter
Retries recover from transient errors, but during an overload they multiply the load on the struggling dependency. Exponential backoff spaces retries out, doubling the delay each time, and jitter, a random component in the delay, stops many clients from retrying in synchronised waves. The AWS SDKs apply both by default and also use a retry token bucket, which stops retrying when most calls are failing, so clients do not make an outage worse.
Retries belong at one layer only: if three layers each retry three times, one failure at the bottom becomes 27 calls. Only idempotent operations can be retried safely, so non-idempotent ones are made idempotent with client tokens or conditional writes. In Step Functions, a Retry rule sets IntervalSeconds, BackoffRate, MaxDelaySeconds and JitterStrategy, and a Catch rule handles what retries cannot fix.
Where AWS services retry for you
Many integrations retry automatically, and designs must account for what happens when retries run out. A Lambda asynchronous invocation is retried twice more with delays, then sent to an on-failure destination or dead-letter queue (DLQ). With SQS, a failed message reappears after the visibility timeout and moves to the queue's DLQ after maxReceiveCount attempts. With Kinesis or DynamoDB Streams, Lambda retries the failed batch and blocks the shard until it succeeds. Bisecting the batch, maximum retry attempts or record age, and an on-failure destination stop one bad record holding up the stream.
EventBridge retries delivery to a target for up to 24 hours, then uses the target's DLQ. SNS retries deliveries to SQS or Lambda according to its delivery policy, with backoff, and then uses the subscription's DLQ. The following table summarises the behaviour.
| Integration | Retry behaviour | When retries are exhausted |
|---|---|---|
| Lambda asynchronous invocation | Two more attempts with delays | On-failure destination or DLQ |
| Lambda with SQS | Message reappears after the visibility timeout | Redrive to the queue's DLQ after maxReceiveCount |
| Lambda with Kinesis or DynamoDB Streams | Retries the batch, blocking the shard | Bisect batch, maximum retry attempts or age, on-failure destination |
| EventBridge targets | Retries for up to 24 hours | DLQ on the target |
| SNS to SQS or Lambda | Delivery policy with backoff | Subscription DLQ |
A mobile application calls an API Gateway endpoint backed by Lambda, which calls DynamoDB. During a brief DynamoDB throttling event, error rates spike far beyond the throttling itself. Investigation shows that the mobile client, the Lambda function's own code and the SDK each retry three times without delay.
Three layers of immediate retries turn each throttled request into as many as 27 calls, which prolongs the throttling. The fix is to retry at one layer, the SDK, with exponential backoff and jitter; to remove the retry loop from the function; and to have the client back off on HTTP 429 or 503 responses rather than retrying immediately.
Why should retries use exponential backoff with jitter?
Show answer
Backoff gives a struggling dependency time to recover, and jitter spreads retries out so clients do not all retry at the same moment.
Exam Tips
Remember for the exam
- Every remote call needs a timeout; nested timeouts must fit inside each other.
- SQS visibility timeout must exceed processing time, or messages are processed twice.
- Use exponential backoff with jitter, and retry at only one layer.
- Retries require idempotent operations.
- Know where AWS integrations retry for you and where failed events go when retries are exhausted.