Non-Blocking Retries with Retry Topics
Learn to use Spring Kafka's @RetryableTopic to perform non-blocking, time-delayed retries that keep your consumer responsive while reprocessing failed messages.
Non-Blocking Retries with Retry Topics is a free Advanced Spring Boot 4: Event-Driven Architecture (Kafka) lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Advanced Spring Boot 4: Event-Driven Architecture (Kafka) learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Problem with Blocking Retries
Blocking retries (Spring Retry) pause the consumer thread between attempts. A long backoff blocks the partition, stalling all later records.
Non-blocking retries solve this by moving failed records to dedicated retry topics.
How Retry Topics Work
When processing fails, the record is forwarded to a retry topic with a delay. A separate listener consumes the retry topic after the delay and tries again.
- The main consumer keeps moving forward.
- Each retry level can have a longer delay.
Enabling RetryableTopic
Annotate your listener with @RetryableTopic. Spring auto-creates the retry and DLT topics.
@RetryableTopic
@KafkaListener(topics = "orders")
public void handle(Order order) {
paymentService.charge(order);
}Configuring Attempts and Backoff
Customize the number of attempts and the delay strategy directly in the annotation.
@RetryableTopic(
attempts = "4",
backoff = @Backoff(delay = 1000, multiplier = 2.0))
@KafkaListener(topics = "orders")
public void handle(Order order) { /* ... */ }Generated Topic Names
By default Spring creates topics like orders-retry-0, orders-retry-1, and finally orders-dlt.
Each retry topic corresponds to one backoff level.
Exponential vs Fixed Backoff
Set multiplier for exponential growth, or omit it for fixed delays.
- Fixed: 1s, 1s, 1s.
- Exponential: 1s, 2s, 4s.
Exponential is better for transient downstream outages.
Selecting Retryable Exceptions
Only retry exceptions that are transient. Use include or exclude to control which exceptions trigger retries.
@RetryableTopic(
include = { RemoteServiceException.class },
exclude = { ValidationException.class })
@KafkaListener(topics = "orders")
public void handle(Order order) { /* ... */ }Handling the DLT
After all attempts fail, the record lands on the DLT. Add a @DltHandler method to react.
@DltHandler
public void handleDlt(Order order) {
log.error("Order permanently failed: {}", order.getId());
}Reading Retry Headers
Retry records carry headers such as the attempt count and original timestamp, letting you log how far a message progressed.
@Header(KafkaHeaders.ORIGINAL_TOPIC) String originalTopicBlocking vs Non-Blocking
Use blocking retries for very short, immediate transients; use non-blocking retry topics when delays are longer and partition throughput matters.
Putting It Together
Non-blocking retries keep consumers responsive while still giving failed messages multiple chances. Combine @RetryableTopic, exponential backoff, exception filtering, and a @DltHandler.
Quick Check
Test your understanding of retry topics.
Recap
You learned non-blocking retries.
@RetryableTopiccreates retry topics automatically.- Configure attempts, backoff, and a multiplier.
- Filter retryable exceptions with include/exclude.
- Use
@DltHandlerfor permanently failed records.
Frequently asked questions
Is the “Non-Blocking Retries with Retry Topics” lesson free?
Yes — the full text of “Non-Blocking Retries with Retry Topics” is free to read here on the web, and the Advanced Spring Boot 4: Event-Driven Architecture (Kafka) course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Advanced Spring Boot 4: Event-Driven Architecture (Kafka) course, upgrade to CoddyKit PRO.
What will I learn in “Non-Blocking Retries with Retry Topics”?
Learn to use Spring Kafka's @RetryableTopic to perform non-blocking, time-delayed retries that keep your consumer responsive while reprocessing failed messages. You practise Advanced Spring Boot 4: Event-Driven Architecture (Kafka) with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Advanced Spring Boot 4: Event-Driven Architecture (Kafka)?
No prior experience is required. Advanced Spring Boot 4: Event-Driven Architecture (Kafka) on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Non-Blocking Retries with Retry Topics” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Advanced Spring Boot 4: Event-Driven Architecture (Kafka) lesson?
Yes. Every Advanced Spring Boot 4: Event-Driven Architecture (Kafka) lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Handling Consumer Exceptions
- Retry Mechanisms with Spring Retry
- Implementing Dead Letter Topics (DLT)
- Non-Blocking Retries with Retry Topics