Dead Letter Queues: The Safety Net Your Pipeline Is Missing
If a document fails processing and you don’t have a dead letter queue, it just vanishes. Here’s how to build the safety net that catches it instead.
Your AI pipeline works great. Documents go in, Claude processes them, results come out.
Then one day, a document fails processing. Claude returns malformed data. Your validation rejects it. Where did it go?
If you don’t have a dead letter queue, it vanished. You have no idea what failed, why it failed, or whether customers are impacted. You’re just missing data and hoping nobody notices.
Every production pipeline needs a safety net for this.
Dead letter queues are boring infrastructure. But they’re the difference between handling a failure and losing it.
What’s a Dead Letter Queue?
A dead letter queue (DLQ) is where failed messages go.
You have a normal queue for documents to process. If a document fails — Lambda throws an error, validation rejects it — instead of disappearing or retrying forever, it goes to the DLQ.
The DLQ is a staging area. You can inspect failures, understand what went wrong, and decide whether to retry or escalate.
Without a DLQ, a failed message is lost forever. With one, it goes to the DLQ where you can investigate and retry.
Why You Need This
Scenario 1: Malformed input. A customer uploads a PDF that’s corrupted or in an unexpected format. Claude can’t process it. The Lambda function throws an error.
Without a DLQ, the error gets logged and the message disappears. The customer’s document vanishes, and they email support asking where their result is.
With a DLQ, the message lands there instead. You investigate, find the problem, email the customer, and ask for a corrected file. When they upload it, you reprocess.
Scenario 2: Downstream integration fails. Claude successfully extracts data from an invoice. But your integration with NetSuite is temporarily down. The Lambda can’t post the result.
Without a DLQ, the data is extracted but never reaches the system — you’re stuck manually hunting for it and retrying by hand. With a DLQ, the failed message waits there until NetSuite recovers, then you replay it. Data reaches the system with no manual work.
Scenario 3: Unexpected edge case. Your validation logic has a bug. It rejects valid data from a new customer because of an edge case you didn’t anticipate.
Without a DLQ, that valid data is just gone — missed customer service calls, missed revenue, no trace of what happened. With a DLQ, the failed messages pile up and the spike gets your attention. You investigate, find the bug, fix it, and replay everything that got rejected.
Scenario 4: Cost runaway. A bug causes your Lambda to make 100x more Claude API calls than it should. Your monthly bill goes from $500 to $50,000. You panic and kill the pipeline.
What happens to the messages that were in flight? Without a DLQ, they’re gone. With one, they landed there when the Lambda crashed. Fix the bug, then replay them with the corrected code.
SQS Dead Letter Queue Setup
SQS makes this easy:
How it works:
- Message arrives in main queue
- Lambda processes it
- If Lambda succeeds, message is deleted from queue
- If Lambda fails (throws error, times out, crashes), message is made visible again
- After 3 failed attempts, message is moved to DLQ
Lambda has a maximum retry count. After that, it’s the queue’s job to route failures.
Lambda and SQS Integration
In your Lambda:
SQS handles the retry logic automatically. You just let the Lambda fail.
Investigating DLQ Messages
Messages pile up in the DLQ. Now what?
Step 1: Monitor DLQ Depth
Set up a CloudWatch alarm:
When the alarm fires, you know something is wrong.
Step 2: Read and Analyze DLQ Messages
Step 3: Categorize the Failure
Is it a bad input, like a customer uploading a corrupted PDF? A code bug, where your validation rejects data that’s actually fine? A service outage, where the Claude API itself was down? Or an integration failure, where a downstream system was unreachable? Each requires a different fix.
Replaying Messages
Once you’ve fixed the root cause, replay the messages.
Or replay selectively, fixing only specific failures:
Operational Pattern
Daily
Check DLQ depth. It should be near zero. If it’s not, investigate why.
When Failures Spike
Pull 10-20 messages from the DLQ and look for patterns — same document type, same time period, same error. Categorize the failure, fix the root cause, then replay the messages.
Weekly
Review DLQ metrics and look for trends. Are failures increasing? What types? Update your validation or error handling based on what you find.
Cleanup
Messages in the DLQ older than 14 days are automatically deleted. Log them for analysis before that happens, and pull out what you learned — “10% of failures are malformed PDFs, so add better input validation” is the kind of note worth keeping.
The Terraform Pattern
The Cost
Dead letter queues cost almost nothing. SQS charges per 64KB block of data — a DLQ holding 100 messages runs pennies a month.
The real cost of skipping one is hidden, and it shows up later as lost data and an emergency debugging session when a customer notices before you do.
A DLQ is cheap insurance. It sits there quietly until the day you need it.
The Pattern
Every queue needs a DLQ, and every async system needs somewhere for failures to land instead of vanishing.
Build it before you deploy, monitor it, and replay failures quickly once you understand them.
Your future self will thank you when the system breaks at 2am and you can investigate calmly instead of guessing.
Get the free AI Readiness Checklist
15 questions to diagnose your team’s AI readiness, where you’ll see ROI fastest, and what to tackle first.
No spam. Unsubscribe anytime.
Ready to build AI that actually works?
Let’s talk about how SRE discipline transforms AI from a risky experiment into a reliable business system.
Book Your Free Discovery Call