Scrivio Interview library
DesignIntermediate7 min read · updated 12 November 2026

Design error handling for a payment-events consumer where some failures are transient (downstream timeouts) and some permanent (invalid data). Compare blocking retries with @RetryableTopic non-blocking retries.

First classify failures: permanent errors such as invalid data go straight to a dead-letter topic, and transient errors such as downstream timeouts are retried with back-off. Blocking retries with DefaultErrorHandler keep per-key order but stall the whole partition while they wait; @RetryableTopic moves the failed record to delayed retry topics so the main topic keeps flowing, at the cost of per-key ordering. For payments, where events for one account must apply in order, I would use bounded blocking retries, or park the account's later events, and back both with a well-run DLT and an idempotent replay path.

Why this question is asked

Payment consumers are where error handling stops being a configuration detail. Retry too little and a short outage of the payment provider turns into thousands of failed payments; retry the wrong way and a refund is applied before the charge it refunds. Interviewers ask this design question to see whether we can weigh ordering against throughput and explain the trade-off in business terms. In this answer, we will classify the failures, look at how blocking and non-blocking retries behave on the same partition, decide which fits payments and why, and plan the dead-letter operations that every design needs.

1Classify the Failures

Every exception the listener can throw falls into one of two groups. A transient failure is one that may succeed if we try again later: a timeout from the payment provider, a 503 from a downstream service, a database deadlock. A permanent failure will fail the same way however often we retry: a payment with a negative amount, an unknown currency, a payload that cannot be parsed, an account id that does not exist.

Retrying a permanent failure only wastes time and, with blocking retries, holds up other payments. So the first design decision is an explicit list. In Spring Kafka, DefaultErrorHandler already treats deserialization and conversion errors as not retryable; we add our own validation exceptions with addNotRetryableExceptions so they go straight to the dead-letter topic. Everything else, or better, an explicit list of transient exceptions, gets retried with exponential back-off, for example 1, 2, 4 and 8 seconds.

Java
@Bean
DefaultErrorHandler paymentErrors(DeadLetterPublishingRecoverer dlt) {
var backOff = new ExponentialBackOffWithMaxRetries(4); // 1 s, 2 s, 4 s, 8 s
backOff.setInitialInterval(1_000);
backOff.setMultiplier(2.0);
var handler = new DefaultErrorHandler(dlt, backOff);
handler.addNotRetryableExceptions(InvalidPaymentException.class, UnknownAccountException.class);
return handler; // invalid data -> payments.DLT at once; timeouts retried for about 15 s
}

2How Blocking Retries Behave

With blocking retries, DefaultErrorHandler seeks the consumer back to the failed record and redelivers it after each back-off. Nothing else in that partition is processed in the meantime. The good news is that order is kept: if account 77 has a charge at offset 500 and a refund at offset 501, the refund cannot overtake the charge.

The cost is that one partition holds payments for many accounts. If the provider is down for two minutes, every account on that partition waits, and lag grows for all of them, not just for account 77. With 12 partitions and an outage that affects every record, the whole topic stalls, which is arguably correct: there is no point racing ahead when every call will fail anyway. The bigger risk is one record that keeps timing out while others would succeed.

3How @RetryableTopic Non-Blocking Retries Behave

Spring Kafka's @RetryableTopic takes a different approach. When the listener fails, the record is published to a retry topic, for example payments-retry-0, and the main listener commits and moves on. A consumer on the retry topic waits until the record's delay has passed, then tries again, and on further failure passes it to the next retry topic, until it finally lands in the DLT.

Java
@RetryableTopic(
attempts = "4", // 1 try + 3 retries
backoff = @Backoff(delay = 2_000, multiplier = 5.0), // 2 s, 10 s, 50 s
exclude = InvalidPaymentException.class, // straight to the DLT
dltStrategy = DltStrategy.FAIL_ON_ERROR)
@KafkaListener(topics = "payments", groupId = "payment-service")
void onPayment(PaymentEvent e) { gateway.capture(e); }
@DltHandler
void onDlt(PaymentEvent e, @Header(KafkaHeaders.ORIGINAL_OFFSET) long offset) {
alerts.paymentParked(e.id(), offset);
}
Step throughAccount 77 with non-blocking retries
paymentsListenerpayments-retry-0Ledger
offset 500: charge 77 (gateway timeout)
publish charge 77 with 2 s delay
offset 501: refund 77
apply refund 77 (no charge yet!)
after 2 s: charge 77 again
apply charge 77

6 messages in order. Play them, or step through them one at a time.

The refund overtakes the charge it refers to.

The main topic keeps flowing, so one slow record no longer delays thousands of others. But look at the account 77 example again: the charge at 500 times out and goes to the retry topic, then the refund at 501 is processed immediately on the main topic. The refund now runs before the charge. Per-key ordering is gone. Whether that matters is the real design question.

4Choosing for Payments

For payment events, order per account usually matters: charges, refunds, reversals and balance updates for one account have to apply in sequence. So I would not use @RetryableTopic for the main flow unless each event is fully independent, for example notifications about completed payments.

Instead I would use blocking retries with a bounded total time, such as the 15 seconds of exponential back-off above, so a short provider hiccup is absorbed without a lot of partition lag. If a record still fails after that, it goes to the DLT. But that alone breaks order again, because the account's next event would be processed without the failed one. The safer pattern is to park the key: when a record for account 77 is dead-lettered, record account 77 as blocked in a small table, and send any later events for 77 to the same parking topic until the failed one is resolved. Other accounts keep flowing, and account 77 resumes in order once an operator fixes and replays its events.

When are non-blocking retries the right call? When events are independent, when the downstream can be down for minutes, and when throughput matters more than sequence. Many systems use both: blocking for the ordered ledger consumer, non-blocking for side consumers such as receipts and analytics.

Blocking vs non-blocking retries
PropertyBlocking (DefaultErrorHandler)Non-blocking (@RetryableTopic)
Per-key orderKeptLost while a record is in a retry topic
Partition during retriesStalled for every keyKeeps flowing
Long delaysMust stay below max.poll.interval.msMinutes are fine
Extra topicsOnly the DLTRetry topics plus the DLT
Good fitLedger, balances, state machinesIndependent notifications

5Planning the Dead-Letter Operations

A DLT is only useful if someone looks at it. For payments, every arrival should raise an alert to the owning team, because each parked record is a customer whose money is in limbo. The DLT record carries headers with the original topic, partition, offset and exception, and we add our own, such as the service version, so triage can start without digging through logs.

Then there must be a safe way back. After fixing the data or the bug, an operator replays the record to the original topic or a dedicated replay topic using shared tooling, not hand-written scripts. Replay is only safe if processing is idempotent: the ledger write is keyed by the payment id, so applying it twice does nothing, and the call to the payment provider carries the payment id as an idempotency key, so a retried capture cannot charge the customer twice.

6Follow-up questions

Who owns the DLT and how are records replayed?

The team that owns the consumer owns its DLT, because only they can tell bad data from a bug in their code. They get the alert, triage within an agreed time, and decide per record: fix and replay, or discard with a recorded reason. Replay goes through a shared tool that reads the DLT, lets the operator edit or select records, and republishes them to the original topic with the original key, so they land on the same partition. Because processing is idempotent by payment id, replaying a record that partly succeeded before is safe.

Why not make the blocking retries very long, say ten minutes?

Because the whole partition waits that long, and because the consumer thread sleeps during the back-off: each delay must stay below max.poll.interval.ms or the group rebalances and the retry starts over on another instance. Long outages are better handled by stopping or pausing the consumer while the downstream is unhealthy, for example with a circuit breaker that pauses the listener container.

7Conclusion

In this answer, we designed error handling for payment events. We split failures into permanent ones that go straight to the DLT and transient ones that are retried with bounded exponential back-off. Blocking retries keep per-key order but stall the partition, while @RetryableTopic keeps the topic moving and gives up per-key order. Because payments for one account must apply in order, we chose bounded blocking retries and parking of an account's later events, and planned DLT ownership, alerting and an idempotent replay path.

What to say in the interviewAbout 80 seconds aloud

Open with

I'd start by classifying exceptions. Invalid data, like an unknown account or a negative amount, is permanent, so it should go straight to the dead-letter topic; I'd register those as not-retryable on DefaultErrorHandler.

Then, if they want more

Timeouts and 5xx responses from downstream are transient, so they get retried with exponential back-off. Then there's the blocking versus non-blocking choice.

Blocking retries seek back and redeliver the same record, which keeps order but stalls the whole partition, so every account on it waits. @RetryableTopic publishes the failed record to delayed retry topics and moves on, so the main topic keeps flowing, but a later event for the same key can overtake the failed one, for example a refund before its charge.

For a payments ledger that's unacceptable, so I'd use blocking retries with a bounded total, say around fifteen seconds, and when a record still fails I'd dead-letter it and park that account's subsequent events until it's resolved, so other accounts keep moving and the account stays in order. Non-blocking retries are fine for independent consumers like receipts.

Finally, the DLT needs an owner, an alert on every arrival, enough headers to triage, and a replay tool, and all processing must be idempotent by payment id, including an idempotency key on the provider call.

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.
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 "Design error handling for a payment-events consumer where some failures are transient...": https://scrivio-interview-library.netlify.app/spring-boot/kafka/cdebd68b8a/