0Pricing
Serverless Backend with AWS Lambda & API Gateway · Lesson

Dead-Letter Queues and Failure Handling

Messages can fail to process. Learn how dead-letter queues capture poison messages, and how to design retries and reprocessing for resilient event-driven systems.

Dead-Letter Queues and Failure Handling is a free Serverless Backend with AWS Lambda & API Gateway lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Serverless Backend with AWS Lambda & API Gateway learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Problem of Failing Messages

In an event-driven system a message may fail repeatedly — bad data, a downstream outage, or a bug. Without a safety net, it can block the queue or be lost forever.

What is a Dead-Letter Queue?

A dead-letter queue (DLQ) is a separate queue that captures messages that could not be processed after a set number of attempts. This isolates poison messages without losing them.

Redrive Policy

An SQS queue routes to a DLQ via a redrive policy that names the DLQ and a maxReceiveCount. After that many failed receives, the message moves to the DLQ.

{
  "deadLetterTargetArn": "arn:aws:sqs:us-east-1:123:orders-dlq",
  "maxReceiveCount": 5
}

Configuring a DLQ for Lambda

Async Lambda invocations (S3, SNS) can send failures to a DLQ or to an on-failure destination via the event invoke config.

aws lambda put-function-event-invoke-config \
  --function-name processOrder \
  --destination-config '{"OnFailure":{"Destination":"arn:aws:sqs:...:orders-dlq"}}'

Setting maxReceiveCount Wisely

Too low and transient blips dead-letter good messages; too high and a poison message wastes many retries. A value of 3 to 5 is a common starting point.

Inspecting Dead-Lettered Messages

Messages in the DLQ keep the original body plus attributes showing why they failed. Read them to diagnose the root cause before reprocessing.

aws sqs receive-message \
  --queue-url https://sqs.../orders-dlq \
  --attribute-names All

Redriving Messages Back

Once the bug is fixed, SQS can redrive messages from the DLQ back to the source queue for reprocessing — no manual copying needed.

Idempotency Matters

Because retries and redrives can deliver the same message more than once, your handler must be idempotent: processing the same message twice should not double-charge or duplicate records.

Alerting on the DLQ

A growing DLQ is a signal something is broken. Set a CloudWatch alarm on the DLQ ApproximateNumberOfMessagesVisible metric to get notified.

Partial Batch Failures

When Lambda reads a batch from SQS, reporting batchItemFailures lets only the failed messages return to the queue, instead of reprocessing the whole batch.

{
  "batchItemFailures": [
    { "itemIdentifier": "msg-id-3" }
  ]
}

Designing for Resilience

A resilient pipeline combines:

  • Retries for transient errors
  • A DLQ for poison messages
  • Idempotent handlers
  • Alarms and a redrive plan

Quick Check

Test your failure-handling knowledge.

Recap

You learned to handle failing messages:

  • A DLQ isolates poison messages after maxReceiveCount
  • Configure redrive policies and Lambda on-failure destinations
  • Inspect, fix, then redrive messages back
  • Make handlers idempotent and alarm on DLQ depth
  • Use batchItemFailures for partial batch retries

Frequently asked questions

Is the “Dead-Letter Queues and Failure Handling” lesson free?

Yes — the full text of “Dead-Letter Queues and Failure Handling” is free to read here on the web, and the Serverless Backend with AWS Lambda & API Gateway course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Serverless Backend with AWS Lambda & API Gateway course, upgrade to CoddyKit PRO.

What will I learn in “Dead-Letter Queues and Failure Handling”?

Messages can fail to process. Learn how dead-letter queues capture poison messages, and how to design retries and reprocessing for resilient event-driven systems. You practise Serverless Backend with AWS Lambda & API Gateway with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Serverless Backend with AWS Lambda & API Gateway?

No prior experience is required. Serverless Backend with AWS Lambda & API Gateway on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Dead-Letter Queues and Failure Handling” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Serverless Backend with AWS Lambda & API Gateway lesson?

Yes. Every Serverless Backend with AWS Lambda & API Gateway lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. SQS for Decoupling Services
  2. SNS for Pub/Sub Messaging
  3. Lambda with SQS/SNS Triggers
  4. Dead-Letter Queues and Failure Handling
← Back to Serverless Backend with AWS Lambda & API Gateway