Handling Transient Failures with Retries, Backoff and Circuit Breakers
This lesson explains how distributed applications handle transient failures, such as throttling and timeouts, without overwhelming the services involved.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish errors that are worth retrying from errors that are not.
- Explain how exponential backoff and jitter prevent retry storms.
- Describe how timeouts, circuit breakers and other techniques stop a failing dependency from spreading failure.
- Explain how the Retry fields of a Step Functions Task state control backoff.
Retrying safely
A retry is useful only when the error is temporary. Throttling errors (HTTP 429) and server errors (HTTP 5xx) usually reflect a momentary condition, such as a burst of traffic or a brief service problem, so the same request is likely to succeed a little later. Most other client errors (HTTP 4xx), such as a validation error or AccessDenied, are caused by the request itself and will fail every time until the code or permissions change, so retrying them only adds load and delay. The following table summarises the rule.
| Error | Retry? |
|---|---|
| Throttling (429) and 5xx server errors | Yes, with exponential backoff and jitter |
| Other 4xx client errors, such as validation or access denied | No, they will fail again |
Even temporary errors need careful retries. If every client retries at once, the retries themselves can overload the service again. The following list describes the techniques that make retries safe.
- Exponential backoff: wait longer after each attempt.
- Jitter: add randomness so many clients do not retry in lockstep.
- SDK retry modes:
standarduses backoff with a retry quota;adaptivealso slows the client when it detects throttling. Maximum attempts are configurable per client.
Example. Exponential backoff with full jitter in application code:
import random, time
def call_with_backoff(fn, attempts=5, base=0.2, cap=10):
for attempt in range(attempts):
try:
return fn()
except TransientError:
if attempt == attempts - 1:
raise
time.sleep(random.uniform(0, min(cap, base * 2 ** attempt)))The following diagram compares retries with and without jitter for two clients throttled at the same moment.

Retry or not?
Protecting against failing dependencies
When a dependency fails or slows down, the danger is that the failure spreads: callers wait, their resources fill up, and soon they fail too. Four techniques contain the damage.
A timeout limits how long a caller waits. Without one, a slow dependency holds threads, database connections or Lambda execution environments until the caller runs out of them, so timeouts should be shorter than the caller's own deadline. A circuit breaker tracks failures. After a threshold is reached it opens, and calls fail at once or return a fallback, such as cached data, without contacting the dependency. After a pause, it lets a test request through and closes again if the dependency has recovered. This gives the dependency time to recover instead of being flooded with retries.
A bulkhead isolates dependencies from one another, so a problem with one cannot consume the capacity needed for others. In Lambda, giving each function reserved concurrency, or sending each kind of work to its own queue, means a backlog in one area does not starve the rest. A dead-letter queue sets aside messages that keep failing, so they stop consuming retries and blocking other work, and can be inspected and redriven later. The following table summarises the techniques.
| Technique | What it does |
|---|---|
| Timeouts | Stop a slow dependency tying up threads, connections or Lambda concurrency |
| Circuit breaker | After repeated failures, stop calling the dependency and fail fast or return a fallback, then test later whether it has recovered |
| Bulkheads | Isolate dependencies with separate concurrency limits, such as reserved concurrency or separate queues |
| Dead-letter queues | Set aside work that keeps failing instead of retrying for ever |
The following diagram shows the three states of a circuit breaker and what moves it between them.

Resilience techniques
Retries in Step Functions
A Task state's Retry field lists the errors to retry, with IntervalSeconds, MaxAttempts, BackoffRate, MaxDelaySeconds and JitterStrategy; Catch sends remaining errors to a fallback state.
Example. With an interval of 2, a backoff rate of 2 and 4 attempts, the retries wait 2, 4, 8 and 16 seconds, giving up about 30 seconds after the first failure. "JitterStrategy": "FULL" randomises each wait.
AWS's reference circuit breaker uses a Step Functions workflow that records each dependency's status in DynamoDB and skips calls while the circuit is open.
Calculate the backoff
A retry storm
A payment provider has a brief outage. Every client retries immediately and repeatedly; when the provider recovers, it is overwhelmed by the backlog of retries and fails again.
| Practice | Effect |
|---|---|
| Exponential backoff | Each retry waits longer: 0.2 s, 0.4 s, 0.8 s... |
| Jitter | Random delays spread retries out so clients do not retry in sync |
| Maximum attempts | Stops retrying after a limit and reports the failure |
| Circuit breaker | After repeated failures, stop calling the provider for a period and fail fast or use a fallback |
| Idempotency keys | Retried payments are not charged twice |
The AWS SDKs apply backoff with jitter automatically; Step Functions applies it through Retry with BackoffRate and JitterStrategy. Code that calls third parties directly must implement it itself.
Why should retries use exponential backoff with jitter?
Show answer
Backoff spaces retries out so a struggling dependency can recover. Jitter randomises the delays so that many clients do not retry at the same moment and cause a retry storm.
Exam Tips
Remember for the exam
- Throttling from an AWS API calls for exponential backoff with jitter.
- To stop hammering a failing third-party service, use a circuit breaker.
- Do not retry 4xx client errors, other than throttling.
- To make a client slow down automatically when throttled, use the SDK's adaptive retry mode.
- To contain the impact of a failing dependency, use bulkheads with separate concurrency limits.