Introduction
A B2B order pipeline processes thousands of events a day from a partner's ERP. One morning, a partner starts sending a new unit of measure the system does not recognize. The consumer retries each event, fails, and retries again, and the queue backs up. Orders that have nothing to do with the new unit wait behind the bad ones. By lunchtime, customers are calling.
The first fix is a dead-letter queue (DLQ): after a set number of failed attempts, move the message aside so the rest can flow. Most teams stop there. The DLQ then grows quietly until someone notices that hundreds of orders were never processed.
In this article you will learn when to dead-letter a message, what to store with it, how to triage failures, and how to build a replay tool that lets operations teams fix and reprocess messages safely.
When to Dead-Letter a Message
Distinguish between transient and permanent failures. Timeouts, rate limits, and temporary database errors deserve retries with backoff. Validation errors, unknown references, and schema mismatches will fail the same way every time; retrying them only wastes capacity.
Dead-letter a message when it has failed a set number of times, or immediately when the error is clearly permanent. Managed queues support this directly, such as an SQS redrive policy with maxReceiveCount or a dead-letter exchange in RabbitMQ. If your pipeline uses Postgres as a queue, a DLQ is simply a table.
What to Store With Each Dead Letter
A dead letter without context is hard to act on. Store the original message unchanged, its headers, the source queue, the consumer and version that failed, the error class and message, the number of attempts, and the first and last failure times.
CREATE TABLE dead_letters (
id bigserial PRIMARY KEY,
source_queue text NOT NULL,
message_id text NOT NULL,
tenant_id bigint,
payload jsonb NOT NULL,
headers jsonb,
consumer text NOT NULL,
consumer_ver text NOT NULL,
error_class text NOT NULL, -- 'validation', 'unknown_reference', 'bug'
error_message text NOT NULL,
attempts int NOT NULL,
first_failed timestamptz NOT NULL,
last_failed timestamptz NOT NULL,
status text NOT NULL DEFAULT 'open' -- open, replayed, discarded
);
Storing the tenant and an error class makes triage possible: "37 open dead letters for tenant 12, all unknown_reference" points to a missing master data sync, not to 37 separate problems.
Building a Replay Tool
A replay tool lets someone select dead letters by filter, see what will happen, and send them back for processing. It needs a few features to be safe:Filtering by source, tenant, error class, and time range.
A dry run that runs validation against current code and data without side effects.
Replay to the original queue, with rate limiting so a large batch does not swamp consumers.
Optional payload correction for a single message, with the edit recorded and attributed.
Discard with a required reason for messages that should never be processed.
Replay is only safe if consumers are idempotent. A message that partly succeeded before failing will be processed again from the start, so every side effect must be keyed and repeatable.
Alerting and Ownership
Alert on the number of open dead letters and on the age of the oldest one, per pipeline. Assign every pipeline an owning team and every error class a default action: fix code and replay, fix master data and replay, or contact the partner. Review the DLQ in a short weekly meeting until it is routinely near empty.
Practical Examples: Real-World Use Cases
In the order pipeline from the introduction, the team added the new unit of measure to the product catalog, ran a dry run on 212 dead letters filtered by error class, and replayed them at 20 per second. All orders were processed within a few minutes, and no duplicates were created.
A logistics SaaS found that most of its dead letters were shipment updates arriving before the shipment itself existed. It added a short delayed retry for unknown references, which cut dead letters by more than 80 percent.
A billing platform gives its support team a replay screen limited to their own customers' events, with discards requiring a ticket reference.
Common Mistakes to Avoid
Retrying permanent failures until they reach the DLQ, delaying healthy messages.
Storing only the error, not the original payload.
No alert on DLQ size or age.
Replay tools that bypass rate limits or idempotency.
Deleting dead letters to clean up dashboards.
Best Practices: Actionable Tips
Classify errors at the consumer and record the class with each dead letter.
Store consumer version so you can tell whether a fix has been deployed.
Provide a replay in an operations UI, not only through a database console.
Record who replayed or discarded each message and why.
Practice a replay in staging after every major pipeline change.
Conclusion
A dead-letter queue stops bad messages from blocking good ones, but it only creates value when someone can understand and reprocess what lands there. Classify failures, store full context, alert on size and age, and build a safe replay tool on top of idempotent consumers. The takeaway: a DLQ is a work queue for people, so design it like one.
Make Your Event Pipelines Recoverable With Parallaxis
Parallaxis builds event-driven systems and cloud infrastructure for B2B companies, including dead-letter handling, replay tools and operational dashboards. If failed messages in your pipelines are found by customers instead of alerts, visit parallaxis.in to explore our cloud and development services or talk to our engineers.


