Kafka Consumer Non-Blocking Retry: Spring Retry Topics

Rob Golder
Lydtech Consulting
Published in
10 min readApr 1, 2023

--

Kafka Consumer Non-Blocking Retry: Spring Retry Topics

When an event is consumed from Kafka by an application but the application is not able to process it then it may be required to retry the event. If the retry is blocking then no other events from the same topic partition will be processed until the event being retried has completed (successfully or otherwise). A non-blocking retry pattern on the other hand ensures that those other events will still be processed while the original event is being retried. Spring Kafka provides a mechanism for retry that is non-blocking. It requires minimal code changes to implement. The trade-off with using this pattern is the loss of guaranteed event ordering.

This article describes how Spring retry topics work, and provides an accompanying Spring Boot application that demonstrates the behaviour. The source code for the application is available here.

For applications not using Spring Kafka, the second part of this article details the design and implementation of a non-blocking retry pattern that achieves the same behaviour.

Blocking vs Non-Blocking Retry

Blocking Retry

If an application is unable to process an event due to a transient problem, such as a downstream service being unavailable, then typically a blocking retry would be…

--

--