Scrivio Interview library
InternalsIntermediate6 min read · updated 13 November 2026

A team built a task queue on a partitioned log. One failing task is retried for 30 minutes and blocks everything behind it in its partition, some tasks must run 15 minutes later, and slow tasks time out and are processed twice.

How would you add per-message acknowledgement, redelivery with backoff and delayed delivery on top of a log-based queue without losing its throughput?

Keep the log for storage and order, but track acknowledgements per message: the committed position becomes the lowest unacknowledged offset, and acknowledged offsets beyond it sit in a set or bitmap, so one slow message no longer blocks the rest. In-flight messages get a lease that workers can extend, expired leases are redelivered from a timer wheel or sorted index, failing messages move to retry queues with growing backoff and then a dead-letter queue, and delayed messages wait in time-bucketed delay topics until a scheduler moves them. Per-message state costs memory and gives up strict order for redeliveries, so it is a subscription mode; Kafka's share groups take a similar approach, so check their maturity in your version.

Why this question is asked

Teams often build task queues on a log like Kafka because it is already there and it is fast. Then they meet the log's nature: a partition is processed in order, so one stuck message stops everything behind it, and there is no built-in notion of 'try this one again later'. Interviewers ask this to see whether we can add queue semantics to a log without destroying what makes it fast. In this answer, we will see why the log blocks, track acknowledgements per message, add leases and redelivery, move failures to retry and dead-letter queues, implement delayed delivery, and look at the cost and at Kafka's own approach.

1Why a Log Blocks Behind One Message

A consumer group stores a single offset per partition: everything before it is done, everything after it is not. If message 1,000 fails and is retried for 30 minutes, the consumer cannot move its committed offset past 1,000, even if it has processed 1,001 to 5,000 in parallel, because one number cannot say 'all done except 1,000'. If it commits anyway, a crash loses message 1,000; if it does not, a crash replays thousands of finished messages. In practice consumers process in order and wait, so the whole partition stalls. And a slow task that exceeds the consumer's session or poll timeout gets its partition reassigned, so another consumer processes it again, which is the double processing in the question.

2Tracking Acknowledgements per Message

We keep the log exactly as it is for storage and order, and change only how progress is tracked. Workers acknowledge individual offsets. The committed position becomes the lowest offset that is not yet acknowledged, and acknowledged offsets beyond it are kept in a set or, more compactly, a bitmap starting at the committed position. When the lowest message is finally acknowledged, the position jumps forward past every contiguous acknowledged offset.

Progress of one partition with per-message acks
OffsetStateEffect on the committed position
998, 999acknowledgedbehind the committed position
1000in flight, retryingcommitted position stays at 1000
1001 to 1063acknowledgedstored as bits in the bitmap
1064 to 1080in flightleases running
1000 acked lateracknowledgedposition jumps to 1064
One stuck message no longer stops work on the 63 behind it.

3Leases, Redelivery and Long Tasks

Each message handed to a worker gets a lease: a deadline, for example 60 seconds, by which it must be acknowledged. The broker or a coordinator keeps the leases in a structure that finds expired ones cheaply, such as a timer wheel, an array of time slots that a clock hand sweeps through, or an index sorted by deadline. When a lease expires, the message becomes available again and goes to another worker.

For tasks that legitimately take longer, the worker extends its lease periodically, a heartbeat that says 'still working on 1,064'. That fixes the double processing: a 15-minute task is not redelivered as long as its worker is alive and extending, while a crashed worker stops extending and its message is redelivered after one lease period.

Step throughA long task with lease extension
WorkerBrokerLease timer
deliver offset 1064, lease 60 s
schedule expiry at t+60
extend 1064 (still working)
move expiry to t+120
ack 1064 after 14 minutes
cancel expiry
(other lease expired: redeliver 1071)

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

4Retry Queues and a Dead-Letter Queue

A message that keeps failing should not keep a slot in the main partition. After a failure, the consumer writes it to a retry topic with a growing backoff, for example retry-1m, retry-10m and retry-1h, and acknowledges the original. A separate consumer reads each retry topic and only processes a message once its delay has passed. After a set number of attempts, say five, the message goes to a dead-letter queue (DLQ) along with the last error and stack trace, where a person or a repair job can inspect it.

The main partition keeps flowing at full speed, and failures are visible in one place instead of hiding as a stalled consumer. Spring Kafka's non-blocking retries with @RetryableTopic follow this exact pattern, creating the retry and DLT topics for us.

Step throughA failing message
  1. Process from the main topicfails with an error
  2. Attempts left?for example 5 attempts
    YesSend to the next retry topicNoSend to the dead-letter queue
  3. Retry consumer waits for the backoff1 minute, 10 minutes, 1 hour
  4. Process againsuccess acknowledges; failure goes back to step 2
  5. Dead-letter queuekeeps payload, error and attempt count

5 steps in order. Play them, or step through them one at a time.

5Delayed Delivery Without Sleeping Consumers

Some tasks must run later, such as a reminder 15 minutes after signup. A consumer that receives such a message and sleeps holds a slot and blocks its partition. Instead, delayed messages are written to time-bucketed delay topics, for example one per minute of due time, or to a timer index keyed by due time. A scheduler reads the bucket whose time has come and publishes those messages to the live topic. Consumers of the live topic then only ever see messages that are due.

Bucketing trades precision for simplicity: with one-minute buckets, a message is delivered within a minute of its due time, which is fine for most business delays. Finer precision needs a sorted timer index.

6What It Costs and Kafka's Own Direction

Per-message state is not free. The broker or coordinator must hold a bitmap and leases for every partition with in-flight work, in memory and in durable metadata writes so a failover does not forget them. Redelivered messages come back after later ones, so strict order is gone for them. And retry topics multiply the number of topics to manage.

So this should be a subscription mode, not a replacement: event streams that need order keep classic offset commits, while task-style consumers opt into per-message acknowledgement on the same log. Kafka itself has moved this way with share groups (KIP-932), where consumers in a share group receive records individually with acquisition locks and per-record acknowledgement. They arrived as early access in Kafka 4.0 and have been maturing since, so check their status and features in your version before relying on them.

7Follow-up questions

Why not just use a separate queue system for tasks?

That is often the right answer, especially if a managed queue such as SQS or a broker like RabbitMQ is already available. Building queue semantics on the log makes sense when the team wants one platform, replay of tasks, or very high throughput.

How do you keep the bitmap small if one message is stuck for hours?

The bitmap only grows with the distance between the committed position and the newest acknowledged offset. A stuck message should move to a retry topic quickly, which lets the position advance and keeps the bitmap short.

What makes a retry safe?

The task must be idempotent, because a lease can expire just as the worker finishes, so the same message may complete twice. Using a deterministic task id with a dedupe check or an upsert makes the second run harmless.

8Conclusion

In this answer, we added queue behaviour to a log without changing its storage. Per-message acknowledgements make the committed position the lowest unacknowledged offset with acknowledged offsets beyond it in a bitmap, so one slow message stops blocking the partition. Leases with extensions stop long tasks from being processed twice, and a timer wheel or sorted index redelivers expired leases. Retry topics with growing backoff and a dead-letter queue keep failures out of the main flow, and time-bucketed delay topics with a scheduler implement delays. Because per-message state costs memory and gives up strict order, it is a subscription mode, like Kafka's share groups, whose maturity should be checked in your version.

What to say in the interviewAbout 80 seconds aloud

Open with

I would keep the log for storage and order but change how progress is tracked. Workers acknowledge individual messages, the committed position is the lowest unacknowledged offset, and acknowledged offsets beyond it are kept in a set or bitmap, so one slow or failing message no longer blocks the rest of the partition.

Then, if they want more

Each in-flight message gets a lease with a deadline; expired leases are found by a timer wheel or sorted index and redelivered, and workers extend leases for long tasks with a heartbeat, so a 15-minute task is not processed twice.

Failing messages go to retry topics with growing backoff, like one minute, ten minutes, an hour, and after a set number of attempts to a dead-letter queue with the error kept, so the main partition keeps flowing.

For delays, I would write delayed messages to time-bucketed delay topics or a timer index and have a scheduler move them to the live topic when due, instead of consumers sleeping.

This per-message state costs memory and metadata writes and gives up strict order for redelivered messages, so I would offer it as a subscription mode next to normal offset commits. Kafka's share groups take a similar approach, so I would check their maturity in our Kafka version.

About this answer

Last updated
13 November 2026
Versions it names
Kafka 4.0
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. 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 "How would you add per-message acknowledgement, redelivery with backoff and delayed...": https://scrivio-interview-library.netlify.app/architecture/system-design-problems/87a15d45d9/