Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

Dead Letter Queues

A Dead Letter Queue (DLQ) is a separate topic that stores messages which cannot be processed successfully. Rather than blocking a consumer, losing the message, or retrying indefinitely, failed messages are moved to the DLQ for later analysis and reprocessing.

Kafka supports several DLQ models. The correct model depends on the consumer API and Kafka version:

Processing modelDLQ ownershipBehavior
Consumer applicationsApplicationThe application publishes the failed record and error metadata to a DLQ, then advances its source offset
Kafka ConnectConnect runtimeCompatible sink connectors can route tolerated record-processing errors to a configured DLQ topic
Kafka Streams 4.2+Streams exception handlerDeserialization, processing, and production exception handlers can return DLQ records
Share groups 4.4+Kafka brokerRejected records, or records released beyond the delivery limit, can be routed to a configured share-group DLQ

Broker-managed share-group DLQs do not replace application-level DLQs. Classic consumers still own their error-routing and offset-commit policy, and applications may need domain-specific metadata or retry workflows beyond the broker feature.


Traditional message brokers (JMS, RabbitMQ, IBM MQ) provide built-in DLQ functionality, typically routing messages based on:

  • TTL expiration - message exceeded time-to-live
  • Delivery failures - maximum delivery attempts exceeded
  • Queue capacity - destination queue full

Application-managed Kafka DLQs serve a different purpose. Since Kafka retains messages regardless of consumption and classic consumers control their own offsets, these DLQs primarily address:

  • Invalid message format - deserialization failures, schema mismatches
  • Bad message content - validation errors, missing required fields
  • Processing failures - business logic exceptions, dependency errors

Share-group DLQs also address delivery mechanics: the broker can route a record after it is explicitly rejected or exceeds its delivery-attempt limit.

Broker-Managed Share-Group DLQs (Kafka 4.4+)

Section titled “Broker-Managed Share-Group DLQs (Kafka 4.4+)”

Share-group DLQs require the cluster feature level share.version=2. They are configured dynamically for each share group rather than in the consumer application.

ConfigurationScopePurpose
errors.deadletterqueue.topic.nameShare groupSelects the DLQ topic
errors.deadletterqueue.auto.create.topics.enableClusterAllows Kafka to create DLQ topics automatically; disabled by default
errors.deadletterqueue.group.enableDLQ topicEnables a manually created topic for broker-managed DLQ writes
errors.deadletterqueue.topic.name.prefixClusterRestricts DLQ topic names; defaults to dlq.
errors.deadletterqueue.copy.record.enableShare groupIncludes the original key, value, and headers; disabled by default

By default, a broker-managed DLQ record contains source metadata such as the group, topic, partition, offset, and delivery count. Enable record copying only after considering payload sensitivity and the additional DLQ storage requirement.


A poison message is a message that causes consumer failure repeatedly. Without proper handling, a single poison message can halt an entire consumer group.

Poison message trapping a consumer in a redelivery loop

CauseDescription
Schema mismatchProducer schema incompatible with consumer’s deserializer
Corrupt dataMalformed JSON, invalid Avro, truncated payload
Business validationData fails domain validation (negative price, invalid date)
Missing dependenciesReferenced entity doesn’t exist in database
Transient failuresDatabase timeout, network error (may succeed on retry)
Code bugsConsumer code throws exception for certain data patterns

The DLQ pattern isolates failed messages so healthy messages continue processing.

DLQ pattern: failed message routed to orders.dlq

BenefitDescription
Fault isolationOne bad message doesn’t block partition processing
No data lossFailed messages preserved for analysis and reprocessing
VisibilityDLQ depth indicates system health issues
DebuggingFailed messages available for root cause analysis
Controlled retryMessages can be reprocessed after fixes deployed

Basic DLQ topology: production flow and error flow

For transient failures, implement multiple retry stages before final DLQ:

Multi-stage DLQ with retry tiers

StrategyImplementationUse Case
Immediate retryConsumer retries N times in-memoryTransient network glitches
Delayed retrySeparate retry topics with consumer pauseRate limiting, backpressure
Exponential backoffIncreasing delays (1s, 5s, 30s, 5m)External service recovery
Scheduled retryTime-windowed reprocessingBatch reconciliation

Organizations must decide between dedicated DLQs per topic or a unified DLQ.

StrategyApproachTrade-offs
Per-topic DLQorders.dlq, payments.dlq, users.dlqTargeted analysis, clear ownership; more topics to manage
Unified DLQSingle application.dlq for all topicsSimpler operations, single dashboard; harder root cause analysis
Per-service DLQorder-service.dlq handles multiple input topicsBalanced approach; requires header-based routing

Most production deployments use per-topic DLQs for clear ownership and targeted alerting.

DLQ messages can remain in Kafka or be moved to external storage for long-term retention and analysis.

DLQ storage options: Kafka-native, hybrid, and external

StorageBest ForConsiderations
Kafka topicStandard use cases, automated reprocessingSet appropriate retention; monitor disk usage
S3/GCS archiveCompliance, long-term retentionBatch reprocessing; requires ETL tooling
Database (PostgreSQL)Manual review workflows, complex remediationEnables UI/CLI tooling; additional infrastructure

A DLQ message should contain the original message plus metadata for debugging and reprocessing.

DLQ message structure: headers, key, and value

HeaderPurpose
dlq.original.topicSource topic name
dlq.original.partitionSource partition
dlq.original.offsetSource offset (for replay tracking)
dlq.original.timestampOriginal message timestamp
dlq.original.keyOriginal message key (if key changed)
dlq.error.messageException message
dlq.error.classException class name
dlq.error.stacktraceStack trace (optional, can be large)
dlq.retry.countNumber of processing attempts
dlq.failed.timestampWhen message was sent to DLQ
dlq.consumer.groupConsumer group that failed
dlq.consumer.instanceSpecific consumer instance

Not all errors should go to the DLQ. Classify errors to determine the appropriate handling strategy.

Error classification decision flow for DLQ routing

CategoryExamplesStrategy
TransientConnection timeout, rate limit, lock contentionRetry with backoff
RecoverableSchema mismatch, validation failure, missing referenceDLQ → fix → reprocess
CorruptInvalid encoding, truncated message, wrong topicDLQ → investigate → discard
PoisonCauses crash/OOM, infinite loop triggerDLQ → immediate alert

DLQ topics should be configured for durability and long retention since messages may need reprocessing weeks later.

# DLQ topic configuration
cleanup.policy=delete
retention.ms=2592000000 # 30 days (longer than main topics)
retention.bytes=-1 # No size limit
min.insync.replicas=2 # Durability
replication.factor=3 # Durability
compression.type=producer # Preserve original compression
StrategyApproachTrade-off
Single partitionAll DLQ messages in one partitionSimple, ordered review; limited throughput
Match sourceSame partition count as source topicPreserves key locality; complex reprocessing
By error typePartition by error categoryEasy triage; custom partitioner needed
Round-robinDefault partitioningBalanced load; no ordering

Error handling approaches compared

ApproachBlockingData LossComplexityBest For
Retry in-placeYesNoLowTransient errors only
Skip and logNoYesLowNon-critical data
DLQNoNoMediumProduction systems
Parking lotNoNoHighCompliance, finance

Preventing malformed records at the producer can reduce DLQ volume. Schema-aware serializers encode records locally and can use Schema Registry to look up or register schemas, depending on their configuration. Encoding and schema-related failures can be handled before the record is sent; schema compatibility checks do not replace business-rule validation.

Producer-side schema validation preventing DLQ messages

StrategyImplementationEffectiveness
Schema RegistryEnforce Avro/Protobuf/JSON Schema at producerCatches format errors before Kafka
Producer validationValidate business rules before sendCatches domain errors at source
Contract testingVerify producer/consumer compatibility in CICatches schema drift before deployment
Input sanitizationClean/normalize data at ingestion boundaryReduces malformed data

Prevention reduces DLQ volume but cannot eliminate it entirely—runtime failures, dependency issues, and edge cases still require DLQ handling.


  • Order processing where every message must be accounted for
  • Financial transactions requiring audit trails
  • Event sourcing where event loss corrupts state
  • Multi-tenant systems where one tenant’s bad data shouldn’t affect others
  • Integration pipelines where upstream data quality varies
  • Metrics/telemetry where occasional loss is acceptable
  • Cache invalidation events (stale cache self-corrects)
  • Heartbeats/health checks
  • High-volume logs where DLQ would be overwhelmed

Anti-Pattern: DLQ as Primary Error Handling

Section titled “Anti-Pattern: DLQ as Primary Error Handling”

DLQ as primary error handling compared with retry and classify

Anti-PatternProblemSolution
No retry before DLQTransient errors flood DLQImplement retry with backoff
DLQ without monitoringSilent failures accumulateAlert on DLQ depth
No reprocessing planDLQ becomes data graveyardBuild reprocessing tooling
Infinite retryPoison messages never reach DLQSet max retry limit
Losing error contextCan’t debug failuresInclude error metadata in headers
Same retention as sourceDLQ expires before reviewLonger DLQ retention
DLQ for backpressureUsing DLQ to handle load spikesScale consumers or use quotas
Connection errors to DLQNetwork timeouts sent to DLQRetry in application; fix connectivity
No DLQ ownershipNobody reviews DLQ messagesAssign data owners, not just infrastructure
Ignoring DLQ entirelyMessages accumulate indefinitelyProcess or archive with defined SLA

Effective DLQ management requires clear ownership and defined processes.

RoleResponsibility
Data ownerReview failed messages, determine if data fix needed
Development teamFix code bugs causing failures, deploy fixes
OperationsMonitor DLQ depth, trigger alerts, manage retention
Platform teamProvide reprocessing tooling, maintain DLQ infrastructure
  • SLA for review - define maximum time messages can remain in DLQ unreviewed
  • Escalation path - who gets notified when DLQ depth exceeds thresholds
  • Reprocessing authority - who can trigger replay of DLQ messages
  • Discard policy - criteria for permanently discarding unrecoverable messages