Video in progress
How does non-blocking retry with @RetryableTopic work, and what does it cost?
A message that fails is sent with a delay to separate retry topics (-retry-0, -retry-1...), while the main partition moves on to the next messages. Processing doesn't stall, but the order for a single key is broken.
📖 Answer
@RetryableTopic(
attempts = "4",
backoff = @Backoff(delay = 1000, multiplier = 3.0),
exclude = ValidationException.class,
dltStrategy = DltStrategy.FAIL_ON_ERROR)
@KafkaListener(topics = "notifications", groupId = "push")
public void send(PushEvent e) {
pushGateway.send(e);
}
@DltHandler
public void dead(PushEvent e) {
log.warn("Push yuborilmadi: {}", e.id());
}
Spring automatically creates the notifications-retry-0, -retry-1, -retry-2 and notifications-dlt topics. The retry topic consumer pauses the partition until the time in the message header arrives.
Compared with blocking retry:
- if an external service is down for 30 seconds, blocking retry holds up the whole partition; non-blocking sets aside only the problem messages;
- but for
order-17, "created" may go off to a retry while "cancelled" gets processed before it.
So I use non-blocking for independent messages (push, email, webhook) and blocking retry + DLT for state changes (orders, accounts).
One more thing: each main topic gets 3-5 extra topics. On clusters where automatic topic creation is off, you have to create them in advance.
Sign up to mark studied questions and save your progress.