AWS Builder Center
Building Resilient Serverless Workflows on AWS: Retries, Dead-Letter Queues, and Observability

Building Resilient Serverless Workflows on AWS: Retries, Dead-Letter Queues, and Observability

Serverless architectures simplify infrastructure management, but they do not eliminate failures. A Lambda function can time out, an external API can become unavailable, or a message can repeatedly fail processing.

An AWS Enthusiast
The real challenge is not preventing every failure. It is designing systems that can detect failures, recover safely, and make problems visible.
In this article, I explore a practical approach to building more resilient event-driven workflows using AWS Lambda, Amazon SQS, and Amazon CloudWatch.

1. A Simple Event-Driven Architecture

Consider an application that processes user-submitted documents.
A basic workflow could look like this:
  1. A user uploads a document to Amazon S3.
  1. An event triggers an AWS Lambda function.
  1. The function validates and processes the document.
  1. The application stores the processing result.
This architecture is easy to start with, but what happens if the function fails or a downstream service becomes temporarily unavailable?
Without appropriate safeguards, events may be lost, processing may stop, or failed messages may repeatedly consume resources.



A resilient serverless document-processing workflow using Amazon S3, SQS, AWS Lambda, and CloudWatch.

2. Use SQS to Decouple Processing

Instead of sending work directly to a processing function, introduce Amazon SQS as a buffer.
A more resilient workflow is:
S3 → SQS → Lambda → Processing Result
This separation provides several benefits:
  • Decoupling: Uploading a document does not depend on immediate processing.
  • Buffering: SQS can hold messages during traffic spikes.
  • Controlled processing: Lambda can consume messages at a managed rate.
  • Recovery: Messages can remain queued while temporary downstream issues are resolved.
For workloads that require ordered processing, Amazon SQS FIFO queues may be appropriate. For many independent tasks, a standard queue offers high throughput and at-least-once delivery.

3. Handle Failures with Retries and Dead-Letter Queues

Retries are useful for transient failures, such as temporary network problems. However, retrying a permanently invalid message indefinitely wastes resources.
A dead-letter queue (DLQ) provides a way to isolate messages that repeatedly fail.
A practical configuration includes:
  • A source SQS queue for incoming work.
  • A redrive policy with a defined maximum receive count.
  • A DLQ for messages that exceed that threshold.
  • An operational process to inspect, correct, and redrive failed messages.
Retries should be bounded and designed with backoff where appropriate. The goal is to give temporary failures a chance to recover without creating an endless retry loop.

4. Make Processing Idempotent

SQS standard queues provide at-least-once delivery, which means a message may be delivered more than once.
This makes idempotency essential.
For example, if a document-processing message is delivered twice, the application should avoid creating duplicate records or charging a user twice.
One approach is to assign each job a unique identifier and record completed jobs in a persistent store. Before performing a side effect, the function checks whether that job has already been processed.
Idempotency does not eliminate duplicate delivery. It makes duplicate delivery safe.

5. Make Failures Observable with CloudWatch

A resilient system also needs visibility. Amazon CloudWatch can help operators understand whether the workflow is healthy.
Useful metrics and alarms include:
Signal
Why it matters
SQS queue depth
Shows whether work is accumulating
Oldest message age
Reveals processing delays
Lambda errors and duration
Helps identify failures and slow execution
DLQ message count
Highlights messages that need investigation
CloudWatch Logs can capture structured information such as job IDs, processing stages, and error details. Avoid logging secrets or unnecessary personal data.
Alarms should be connected to a clear response process. An alert is useful only when someone knows what to investigate and how to recover.

6. A Practical Reliability Checklist

Before deploying an event-driven workflow, ask:
  • Are transient failures retried safely?
  • Is there a DLQ for repeatedly failing messages?
  • Is processing idempotent?
  • Can queue backlogs and processing errors be monitored?
  • Are alarms tied to actionable response steps?
  • Can failed messages be investigated and replayed safely?

Conclusion

Serverless systems still require deliberate reliability engineering. SQS buffering, bounded retries, dead-letter queues, idempotent processing, and CloudWatch observability work together to make event-driven applications easier to operate.
The key lesson is that reliability is not achieved by assuming functions will never fail—it comes from designing what happens when they do.
For developers learning AWS and DevOps, building and testing this small workflow is a useful hands-on exercise in fault tolerance, monitoring, and operational readiness.
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