Home/Learn/Apache Kafka/Dead Letter Topics (DLT)

Dead Letter Topics (DLT)

Intermediate
Consumers

A Dead Letter Topic stores messages that a consumer has failed to process after all retry attempts. It enables non-blocking error handling and deferred reprocessing.

Overview

Without DLT, a poison-pill message blocks the consumer forever or causes skipped messages. DLT patterns let the consumer park failed messages and continue, while an ops team can inspect and reprocess DLT messages once the underlying bug is fixed.

Spring Kafka DLT Configuration

Spring Kafka's DefaultErrorHandler with DeadLetterPublishingRecoverer handles retries and DLT routing automatically.

Spring Kafka — DLT with DefaultErrorHandler
@Configuration
public class KafkaConfig {
    @Bean
    public DefaultErrorHandler errorHandler(KafkaTemplate<Object, Object> template) {
        DeadLetterPublishingRecoverer recoverer =
            new DeadLetterPublishingRecoverer(template,
                (r, e) -> new TopicPartition(r.topic() + ".DLT", r.partition()));
        BackOff backOff = new FixedBackOff(2000L, 3L); // 3 retries, 2s gap
        return new DefaultErrorHandler(recoverer, backOff);
    }
}

@KafkaListener(topics = "orders.DLT", groupId = "dlt-processor")
public void handleDlt(ConsumerRecord<String, Order> record,
        @Header(KafkaHeaders.EXCEPTION_MESSAGE) String errorMsg) {
    log.error("DLT: key={} error={}", record.key(), errorMsg);
}

Key Points to Remember

  • 1DLT prevents a poison-pill message from blocking the entire partition
  • 2Naming convention: {topic}.DLT; same partition preserves ordering
  • 3DeadLetterPublishingRecoverer routes to DLT after all retries exhausted
  • 4DLT headers contain exception class, message, and stack trace
  • 5Monitor DLT topic size — growing DLT signals repeated failures

Interview Questions

Sign in to ask Aria
1

What is a Dead Letter Topic in Kafka and why is it needed?

EasyInfosys
2

How does Spring Kafka's DefaultErrorHandler route messages to a DLT?

MediumAmazon
3

What is a poison-pill message and how does DLT prevent consumer blocking?

MediumFlipkart
4

How would you implement retry with exponential back-off before sending to DLT?

HardNetflix
5

How do you safely reprocess messages from a DLT after fixing the underlying bug?

HardUber

Ask Aria about Dead Letter Topics (DLT)

Your personal AI tutor — ask anything about this concept

Revision Status

Personal Notes

Sign in to save personal notes for this topic.

Discussion

Sign in to join the discussion.

Loading discussion…