All guides

Tutorial

Use a Dead-Letter Queue for Agent Jobs

The Queue Where Failures Go to Be Understood

A dead-letter queue holds messages that could not be processed after the retries were exhausted. Its purpose is not storage; it is that nothing is silently dropped and that failures can be inspected in one place.

Without one, a failed message is a log line that nobody reads, and the work it represented is simply lost.

What Belongs in It

Four categories, and the payload should say which.

Permanent failures, such as a validation error or a missing record.

Exhausted retries, where the cause is unknown.

Poison messages, which fail every time and would loop forever if retried.

Unprocessable by design, such as a message for a tenant that no longer exists.

The category determines the response: fix and replay, investigate, or discard with a reason.

What to Record With Each Message

Six fields.

The original payload, unmodified. The error class and message from the final attempt. The attempt count and the timestamps. The step at which it failed. The correlation identifier. And the source queue or automation.

The second and fifth are what make the difference between a queue that gets triaged and one that becomes a graveyard.

The Operational Discipline

A dead-letter queue that nobody reads is worse than none, because it creates the belief that failures are handled.

Three practices.

Alert on depth, not on every message: a threshold above the normal rate, or any message older than an hour.

A weekly review, short, that classifies the contents and either fixes or discards with a reason.

A target of zero at the end of each week, which forces the decision rather than allowing accumulation.

Replay

The most useful feature of a dead-letter queue, and the one that needs care.

Three rules.

Replay is explicit, one message or a filtered set, never everything.

Replay is idempotent, so a message replayed after a partial success does not duplicate the effect.

Replay is recorded, with who did it and when, because a replay is a state change in the outside world.

The second is the reason the idempotency work matters: without it, replay is unsafe and the queue becomes a museum.

Automatic Versus Manual

Two policies, and the right one depends on the failure class.

Automatic replay for a filtered set: transient failures with a retry after timestamp, where the condition is expected to resolve.

Manual for everything else, because a permanent failure replayed automatically is a loop with extra steps.

A common design: automatic for one hour, then manual. That handles the transient case and stops the loop.

Poison Messages

A message that fails identically every time, and which would consume the queue if retried.

Three responses.

Quarantine it on the second identical failure, with the payload and the error, and alert.

Fix the cause, which is usually a data shape the code does not handle.

Discard with a reason, after confirming the work can be done another way.

The second is the right answer most of the time, and the first is what makes it possible to find.

What Not to Put in a Dead-Letter Queue

Three things.

Messages that can be reprocessed by a sweep. If a scheduled reconciliation would pick them up, the queue is a duplicate mechanism.

Messages with no owner, which will never be triaged.

Personal data without a retention policy, since a dead-letter queue is a store of failures that often contains customer information.

Measuring It

Three numbers.

Depth, over time, which should be near zero.

Time to resolution, per message, which reveals whether the review is real.

Replay success rate, which shows whether the failures were understood.

A queue where depth is flat and the age of the oldest message is measured in months is a queue that has been abandoned.

Next step

Read compensating actions for the failures that need a reversal, or contact us to review failure handling.

FAQ

Question: Should the dead-letter queue be a separate system?

It can be a table with a status. What matters is that it is queryable, alertable and reviewed, not which technology holds it.

Question: How long should messages be retained?

Thirty days for triage, with personal data redacted or removed after the review. Longer retention needs a reason.

Question: Can we skip it and just alert?

Alerting without storing loses the payload, which is what a replay needs. Store, then alert.

Next step

Talk to us about the work.

Tell us what you want an agent to run. We come back with a scope, not a slide deck.