Retries, backoff, and DLQs
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
retry transient failures sensibly and park permanent ones.
Planned topics
- Transient failures (timeout, deadlock) deserve a retry; permanent ones (bad payload, rule violation) never succeed.
- Use exponential backoff with a maximum attempt count; blocking retries stall the partition, so use retry topics for long delays.
- After the limit, send the message to a dead-letter queue (DLQ) with the error and original headers.
- Alert on DLQ depth and provide a way to replay after the fix.
- Spring Kafka offers
DefaultErrorHandlerwith backoff and a dead-letter recoverer (verify version before recording).
Draft outline details
Demonstration
var handler = new DefaultErrorHandler(
new DeadLetterPublishingRecoverer(template),
new ExponentialBackOff(500, 2.0)); // add a max elapsed time or attemptsCheck your understanding
Why should a malformed payload go straight to the DLQ?
Show answer
Retrying cannot fix it and only delays the messages behind it.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.