An order events topic has a dead letter queue configured. Any message failing five times goes there instead of blocking the partition. This is correct and it is the standard advice.
Eight months later someone opens the DLQ topic out of curiosity and finds 3,400 messages. The oldest is from the week the feature launched. Among them are 60 cancellations that were never processed, so 60 customers were charged for subscriptions they cancelled.
Nothing alerted. The main topic flowed the entire time. Every dashboard was green, because from the pipeline’s point of view nothing was failing: the failures had been successfully moved somewhere else.
Moving the problem is only half the design
The DLQ solves a real problem. Without one, a message that cannot be processed blocks its partition forever, since Kafka consumers commit offsets in order. One malformed payload stops everything behind it, and that is worse.
So routing it aside is right. What is missing is that a queue is not a decision. Moving a message to a DLQ defers the decision, and deferring only works if something eventually makes it.
flowchart TB
M["Message fails 5 times"] --> DLQ[("Dead letter queue")]
DLQ --> Q{"Who consumes this?"}
Q -->|"nothing"| LOST["Accumulates silently.<br/>Data loss with extra steps."]
Q -->|"alert + owner + replay"| FIXED["Investigated, fixed, replayed"]
style LOST stroke:#ef4444,stroke-width:3px,color:#fff
style FIXED stroke:#4ade80,stroke-width:2px,color:#fff
The uncomfortable framing is that a DLQ with no consumer is functionally identical to dropping the message, except it costs storage and creates the impression that the data is recoverable. That impression is what stops anyone looking.
Context has to be captured at failure time
By the time someone investigates, everything that explains the failure is gone. The consumer has been redeployed twice. The downstream service that was returning 500s has been fixed. The feature flag that was set has been removed.
All that remains is a payload, and a payload does not tell you why it failed.
private ProducerRecord<String, byte[]> toDeadLetter(
ConsumerRecord<String, byte[]> record, Exception failure, int attempts) {
ProducerRecord<String, byte[]> dlq =
new ProducerRecord<>(dlqTopic, record.key(), record.value());
// Everything an engineer will need weeks from now, when none of this
// is reconstructable from anywhere else.
dlq.headers()
.add("dlq.source.topic", record.topic().getBytes(UTF_8))
.add("dlq.source.partition", String.valueOf(record.partition()).getBytes(UTF_8))
.add("dlq.source.offset", String.valueOf(record.offset()).getBytes(UTF_8))
.add("dlq.failed.at", Instant.now().toString().getBytes(UTF_8))
.add("dlq.attempts", String.valueOf(attempts).getBytes(UTF_8))
.add("dlq.exception.class", failure.getClass().getName().getBytes(UTF_8))
.add("dlq.exception.msg", String.valueOf(failure.getMessage()).getBytes(UTF_8))
.add("dlq.consumer.version", buildInfo.version().getBytes(UTF_8));
return dlq;
}
The exception class is the single most useful field, because it separates the three cases that matter and that otherwise look identical.
A deserialisation error means the payload is genuinely bad and replaying it will fail again forever.
A timeout or connection error means a dependency was down and replaying it now will probably succeed.
A null pointer or illegal state means a bug in the consumer, and whether replay works depends entirely on whether that bug has been fixed since.
Without the exception recorded, an engineer looking at 3,400 messages cannot tell which pile is which, and the safest-feeling action is to do nothing.
Not everything belongs in a DLQ
Sending every failure to the DLQ is the mistake that fills it with noise and buries the messages that matter.
A transient failure should be retried, not dead lettered. A downstream service returning 503 for thirty seconds should not produce thirty seconds of DLQ traffic; it should produce retries with backoff, ideally with the consumer pausing the partition rather than spinning.
try {
process(record);
} catch (TransientException e) {
// Do not commit. Pause and let the poll loop retry from this offset.
consumer.pause(Set.of(partition));
scheduleResume(partition, backoff.next());
} catch (PoisonMessageException e) {
// Genuinely unprocessable. This one belongs in the DLQ.
deadLetterProducer.send(toDeadLetter(record, e, attempts));
consumer.commitSync();
}
Distinguishing the two requires the consumer to classify its own exceptions, which is a small amount of work that determines whether the DLQ is a signal or a landfill.
Kafka does not have a native DLQ, so this is application code or a framework feature such as Spring Kafka’s DeadLetterPublishingRecoverer. SQS and RabbitMQ have it built in with a redrive policy, which is more convenient and does not remove the need to consume it.
Replay is a decision, not a button
Replaying a DLQ is where the second class of incident comes from.
An order event from eight months ago is not obviously safe to reprocess. The customer may have cancelled. The price may have changed. The downstream system may have been reconciled manually already. Replaying it applies a state transition that assumes a world that no longer exists.
The properties that make replay survivable are the same ones that make any reprocessing survivable: consumers must be idempotent so a message that partially succeeded before does not double apply, and the handler should check whether the operation is still valid rather than assuming it is. Replaying events without accounting for the side effects they originally caused is a category of failure in its own right, and it applies to any reprocessing rather than only to DLQs.
Replay should also go through the normal topic rather than straight into the consumer, so that everything downstream sees it in the ordinary way and any deduplication in the path applies.
And it should be rate limited. Dumping 3,400 messages into a live pipeline at once is a load spike into a system sized for steady state.
What makes a DLQ real
An owner, named, whose job it is to look at it. Not a team, a person on a rota, because a queue owned by everyone is owned by no one.
An alert on depth and on age of the oldest message. Age is the better signal: a DLQ that receives one message a week and clears it is healthy, and one holding a message from March is not, regardless of count.
A dashboard grouping by exception class, so a spike of one type is distinguishable from a steady trickle of many.
A documented and rehearsed replay procedure, including how to filter out messages that are no longer valid.
And a retention period on the DLQ itself that is longer than the main topic’s, because the whole point is to keep the thing that failed for longer than the thing that succeeded.
// SPONSORSHIP
If this research saved you time or improved your architecture, consider sponsoring my work on GitHub. All sponsorships go directly toward infrastructure and further technical research.
[ Become a Sponsor ]