Quick revision
The short answer
By default the Kafka binder retries a failed message in memory, up to max-attempts (3 by default, so the first try plus two retries) with an exponential back-off, and when the attempts run out it logs the error and moves on, so the message is effectively skipped. To keep failed messages, we set spring.cloud.stream.kafka.bindings.<name>.consumer.enable-dlq=true, optionally with dlq-name, and the binder publishes them to a dead-letter topic. We mark permanent errors as non-retryable so they go straight to the DLQ, and we keep back-offs short, because retries block the partition and increase lag.
What to remember
In this answer, we saw that the Kafka binder retries a failed message in memory up to max-attempts, 3 by default with an exponential back-off, and then logs and skips it. Enabling enable-dlq, with an optional dlq-name, keeps failed messages in a dead-letter topic with headers that describe the failure. We marked permanent errors as non-retryable so they reach the DLQ immediately, and kept retries short because they block the partition, raise lag and can trigger a rebalance.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
By default the Kafka binder retries a failed message in memory, up to max-attempts (3 by default, so the first try plus two retries) with an exponential back-off, and when the attempts run out it logs the error and moves on, so the message is effectively skipped. To keep failed messages, we set spring.cloud.stream.kafka.bindings.<name>.consumer.enable-dlq=true, optionally with dlq-name, and the binder publishes them to a dead-letter topic. We mark permanent errors as non-retryable so they go straight to the DLQ, and we keep back-offs short, because retries block the partition and increase lag.
Why this question is asked
Every consumer meets messages it cannot process: malformed JSON, a missing customer, a downstream service that is briefly down. What the framework does with them by default decides whether we lose data quietly or stall a partition for minutes. Interviewers ask this to check that we know the defaults before we tune them. In this answer, we will recap the binder's retry loop, see what happens when retries run out, enable a dead-letter queue, separate retryable from permanent errors, and look at the cost of retrying on a Kafka partition.
1A Quick Recap of the Binder's Retry Loop
When our function throws an exception for a message, the Kafka binder does not give up immediately. It retries the call in memory, on the same consumer thread, using settings on the input binding. The defaults are max-attempts=3, back-off-initial-interval=1000 milliseconds, back-off-multiplier=2.0 and back-off-max-interval=10000 milliseconds.
Notice that max-attempts counts the first try, so the default means two retries. Setting it to 1 turns retries off entirely.
2What Happens When Retries Run Out
With no further configuration, the binder logs the exception after the last attempt and treats the message as handled. The consumer commits the offset and continues with the next record. In practice the message is skipped: it is still in the topic until retention removes it, but our consumer group has moved past it and nothing will process it again.
That default keeps the partition flowing, which is reasonable for some data, but for payments it means silent loss. The fix is a dead-letter queue, a separate topic that holds the messages that could not be processed, so someone can inspect them and replay them.
- Function throwsfor record at offset 42
- Exception retryable?YesRetry with back-offNoSkip remaining retries
- Attempts left?YesCall the function againNoRetries exhausted
- DLQ enabled?YesPublish record to DLQ topicNoLog the error only
- Commit offset 42continue with offset 43
5 steps in order. Play them, or step through them one at a time.
Without a DLQ, the last step quietly skips the message.
3Enabling a Dead-Letter Queue
The dead-letter queue is a Kafka-binder setting, so it lives under the spring.cloud.stream.kafka prefix rather than the common bindings prefix.
The binder publishes the original record, with its key and value, and adds headers that describe the failure, such as the original topic, partition and offset and the exception message. That is enough to understand what failed and, after a fix, to replay the record to the original topic. The DLQ needs a group, because the binder includes it in the default name, and the DLQ topic needs alerting: a growing DLQ is work that did not happen.
4Retryable and Non-Retryable Exceptions
Retrying makes sense for temporary errors, such as a timeout calling the ledger. It makes no sense for permanent ones: a message whose JSON cannot be parsed will fail the same way three times, delaying everything behind it for no gain. We tell the binder which exceptions are which.
We can also flip the default with default-retryable=false and list only the exceptions worth retrying. Either way, the aim is that a bad message reaches the DLQ in milliseconds while a temporary failure gets its chance to recover.
5Why Retries Block the Partition
There is a catch with in-memory retries. Kafka consumers read each partition in order and commit one offset per partition, so while the binder waits and retries record 42, records 43, 44 and the rest of that partition wait too. With the default settings that is about 3 seconds per failing record. If we raise max-attempts to 10 with a 10-second maximum back-off, one bad record can hold its partition for more than a minute, consumer lag climbs, and if the total wait passes the consumer's max.poll.interval.ms (5 minutes by default), Kafka considers the consumer dead and rebalances the group.
So we keep in-memory retries short, a few attempts over a few seconds, and send anything longer to the DLQ or to separate retry topics that are consumed with a delay, which do not block the main partition. Error handling in the Kafka binder has changed across versions, with newer versions building on Spring Kafka's error handlers, so we check the options our version offers, such as a custom DLQ destination resolver or a container customizer.
6Follow-up questions
Where are the retries done: in the binder or in Kafka?
In the binder, in our consumer's memory, using a retry template around the function call. Kafka itself knows nothing about them; the record is only fetched once. That is why retries hold up the partition and why the consumer must finish them within the poll interval.
How do we reprocess messages from the DLQ?
After fixing the cause, we run a small consumer, or a Spring Cloud Stream function bound to the DLQ topic, that publishes each record back to the original topic. Because the consumer may now see some messages twice, it must be idempotent, for example by checking the payment id before settling.
Does the RabbitMQ binder work the same way?
The retry settings are the same common binding properties. Dead-lettering uses RabbitMQ's own mechanism: with auto-bind-dlq=true the binder creates a dead-letter queue and binds it, and failed messages are rejected into it. Because RabbitMQ acknowledges per message, a failing message does not block others in the same way.
7Conclusion
In this answer, we saw that the Kafka binder retries a failed message in memory up to max-attempts, 3 by default with an exponential back-off, and then logs and skips it. Enabling enable-dlq, with an optional dlq-name, keeps failed messages in a dead-letter topic with headers that describe the failure. We marked permanent errors as non-retryable so they reach the DLQ immediately, and kept retries short because they block the partition, raise lag and can trigger a rebalance.
Open with
By default, when my function throws, the Kafka binder retries the call in memory on the same thread. The defaults are max-attempts three, counting the first try, with a back-off starting at one second, doubling, capped at ten seconds.
Then, if they want more
When the attempts run out and nothing else is configured, the binder just logs the error and commits the offset, so the message is effectively skipped. That's fine for some data, but for something like payments it's silent loss.
So I'd enable a dead-letter queue with spring.cloud.stream.kafka.bindings, the binding name, consumer.enable-dlq equals true, and usually set dlq-name; otherwise it defaults to error dot destination dot group. The binder publishes the original record with headers describing the original topic, offset and exception, and I'd alert on that topic and have a replay tool.
Next I'd separate errors: things like conversion errors or validation failures are permanent, so I mark them non-retryable with retryable-exceptions and they go straight to the DLQ, while timeouts get retried. Finally, I'd keep retries short. They block the whole partition, so a long back-off raises lag and can even exceed max.poll.interval.ms and trigger a rebalance.
Longer waits belong in delayed retry topics, and I'd check what error-handling options our binder version offers.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Cloud Stream reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A Spring Cloud Stream consumer using the Kafka binder fails on some messages. Explain...": https://scrivio-interview-library.netlify.app/spring-boot/spring-cloud-stream/558bb4e5c1/