AWS Builder Center

Retries Can Save Your Application—or Take It Down. 🔄💥

Retries can improve reliability, but poorly designed retry logic can turn a small failure into a larger outage. This article explains exponential backoff, jitter, timeouts, idempotency, and retry limits, along with how Amazon SQS and AWS Lambda can help build safer, more resilient applications.

AWS Builder | Exploring Cloud, Sharing Ideas & Growing Through the Community 🚀

Retries Can Save Your Application—or Take It Down. 🔄💥

When an API request fails, the first solution that comes to mind is simple:
Try again.
And sometimes, that is exactly what your application should do.
But retries can also make an outage worse if they are not designed carefully.

🔄 Why Do We Retry?

Not every failure is permanent. A request might fail because of a temporary network issue, timeout, or short-lived service overload.
A retry gives the system another chance:
1
Request → Failure → Wait → Retry → Success
The problem starts when applications retry too aggressively.
Imagine 1,000 requests fail at the same time. If all 1,000 immediately retry, the already struggling service receives another 1,000 requests.
If those fail again, the traffic can keep increasing.
This is known as a retry storm.

⏳ Use Exponential Backoff

Instead of retrying immediately, increase the delay between attempts:
1
2
3
4
5
6
7
8
9
10
11
Attempt 1 → Failure
↓
100 ms
↓
Attempt 2 → Failure
↓
200 ms
↓
Attempt 3 → Failure
↓
400 ms
Adding jitter, or a small amount of randomness to these delays, prevents many clients from retrying at exactly the same time.

🛑 Don't Retry Everything

A retry only helps when the failure might be temporary.
For example:
1
2
3
Temporary failure → Retry may help
Invalid request → Retry won't fix it
Unauthorized → Retry won'
t fix it
So retry logic should understand which failures are actually retriable.

🔐 Don't Forget Idempotency

Retries can create another problem: duplicate operations.
Imagine a payment succeeds, but the response never reaches the application. The application retries the payment.
Without protection, the same payment could potentially be processed twice.
Idempotency keys can help a service recognize that a request has already been processed.
This is especially important for payments, orders, and other operations where duplicates have real consequences.

📬 Where AWS Can Help

AWS services can help build safer asynchronous architectures.
Amazon SQS can hold messages while a downstream service is busy or temporarily unavailable. Failed messages can also be moved to a dead-letter queue (DLQ) after repeated unsuccessful processing.
AWS Lambda can process queued events without requiring the application to constantly retry requests itself.
The goal isn't simply to add retries.
It's to control how failures move through the system.

✅ A Good Retry Strategy

Before adding retries, ask:
  • Is this failure temporary?
  • How many times should we retry?
  • How long should we wait?
  • Could a retry create a duplicate operation?
  • What happens after all retries fail?
A simple strategy is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Request
↓
Failure?
↓
Retryable?
├── No → Return failure
└── Yes
↓
Backoff + Jitter
↓
Retry
↓
Retry limit reached?
↓
DLQ / Failure

🚀 Final Thought

Retries are useful because failures are inevitable.
But retrying harder isn't always recovering faster.
A reliable system knows when to retry, how long to wait, and when to stop.
Sometimes the smartest retry strategy is knowing when not to retry. 🔄☁️
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article