Bird
0
0

How can you design a Kafka consumer to retry processing failed messages up to 5 times before routing them to a Dead Letter Queue?

hard📝 Application Q9 of 15
Kafka - Event-Driven Architecture
How can you design a Kafka consumer to retry processing failed messages up to 5 times before routing them to a Dead Letter Queue?
AUse Kafka Streams API with built-in retry and DLQ support without custom logic
BConfigure Kafka consumer with max.poll.records=5 and rely on automatic retries
CImplement a retry counter in message headers and on failure increment it; send to DLQ if count exceeds 5
DSet consumer property retries=5 and enable DLQ in the broker configuration
Step-by-Step Solution
Solution:
  1. Step 1: Understand retry logic

    Kafka consumers do not have built-in retry counters; you must implement retry tracking manually.
  2. Step 2: Use message headers

    Adding a retry count header allows tracking how many times a message was retried.
  3. Step 3: Route to DLQ after max retries

    When retry count exceeds 5, send the message to the DLQ topic.
  4. Final Answer:

    Implement a retry counter in message headers and on failure increment it; send to DLQ if count exceeds 5 -> Option C
  5. Quick Check:

    Manual retry count in headers controls DLQ routing [OK]
Quick Trick: Use header retry count to limit retries before DLQ [OK]
Common Mistakes:
  • Assuming Kafka consumer retries automatically
  • Confusing consumer config with broker-level retry
  • Relying on Kafka Streams without custom retry logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes