Quick revision
The short answer
I would first check the consumer logs for rebalances or processing longer than max.poll.interval.ms, because both cause uncommitted records to be delivered again, and then check whether producers retried or upstream services emitted the same event more than once. The fix is to deduplicate by notification id in a store checked before sending and to record each send, to pass an idempotency or collapse key to the push provider where it is supported, and to keep processing per record short or commit offsets more often so fewer records are redelivered.
What to remember
In this answer, we traced duplicate pushes to Kafka's at-least-once delivery. We checked the consumer for rebalances and polls that exceed max.poll.interval.ms, then the producer and upstream services for repeated events. We fixed it by deduplicating on a stable notification id before sending and recording each send, passing collapse or idempotency keys to the push provider, and keeping processing per poll short with more frequent commits so fewer records are redelivered.
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.
I would first check the consumer logs for rebalances or processing longer than max.poll.interval.ms, because both cause uncommitted records to be delivered again, and then check whether producers retried or upstream services emitted the same event more than once. The fix is to deduplicate by notification id in a store checked before sending and to record each send, to pass an idempotency or collapse key to the push provider where it is supported, and to keep processing per record short or commit offsets more often so fewer records are redelivered.
Why this question is asked
Receiving the same push notification three times is annoying for users and damaging for trust; they start muting the app. In a Kafka-based notification worker it is also a sign that the system is doing exactly what Kafka promises, at-least-once delivery, without the application doing its part. Interviewers ask this debugging question to see whether we can find where the duplicates come from and fix them at the right layer. In this answer, we will recap why Kafka redelivers, look for consumer-side causes, look for producer-side and upstream causes, then deduplicate before sending, use provider keys and reduce redelivery at the source.
1A Quick Recap: Why Kafka Redelivers
A Kafka consumer reads records from a partition and periodically commits its offset, the position up to which it has finished. If the consumer stops before committing, for whatever reason, the partition is assigned to another consumer (or the same one after restart), which starts from the last committed offset. Every record processed but not yet committed is processed again. This is at-least-once delivery, and it means any side effect, such as sending a push, can happen more than once unless the application prevents it.
So three copies of the same push suggest the same record was processed three times, or that three separate records described the same notification. The investigation separates these two cases.
2Checking the Consumer: Rebalances and Slow Processing
The most common cause is a rebalance loop. Suppose the worker receives 500 records per poll (max.poll.records defaults to 500) and calls the push provider for each, taking 800 ms when the provider is slow. One poll then takes 400 seconds, longer than max.poll.interval.ms, which is 300,000 ms (5 minutes) by default. Kafka decides the consumer is stuck, removes it from the group and reassigns its partitions. The new owner starts from the last committed offset and sends the same pushes again; if it is also slow, the cycle repeats.
7 messages in order. Play them, or step through them one at a time.
Everything A sent but did not commit is sent again by B.
The evidence is in the logs and metrics: messages from the consumer coordinator about leaving the group or rebalancing, warnings that the poll interval was exceeded (the exact wording depends on the client version, so check your version), and a rising rebalance count in the consumer metrics. Correlating the duplicate push timestamps with rebalance times usually confirms it. Deployments are a second consumer-side cause: every rolling restart triggers rebalances, and records processed but not committed before shutdown are redelivered.
3Checking the Producer and Upstream
If the consumer is healthy, look at the topic itself. Find the three duplicate pushes and look up the Kafka records that caused them, by notification id, user and time. If there are three distinct records with the same content, the duplicates were produced.
Producer retries can write a record twice when a send times out after the broker had stored it; the idempotent producer, enable.idempotence=true, which is the default in recent Kafka clients, prevents this within a producer session. More often the cause is further upstream: the service that requested the notification published the event, failed afterwards and retried its whole operation, or two services both emitted a notification for the same business event. That case needs a stable business id on the notification request, such as orderId plus notification type, so duplicates can be recognised.
4Deduplicating Before Sending
Whatever the source, the reliable fix is in the worker: before sending, check whether this notification id has already been sent, and record the send. A database table with a unique key on the notification id works well, or Redis SET with NX and an expiry for high volumes.
Notice the narrow window that remains: if the worker crashes after the provider accepted the push but before markSent, a redelivered record finds the row in SENDING and sends again. That is why the provider key in the next section matters, and why the row should be marked as soon as the provider responds. For a notification id produced upstream to be useful, it must be stable across retries, which is why the id belongs on the request, not generated in the worker.
5Using the Provider's Keys
Push services offer ways to collapse or replace messages. Firebase Cloud Messaging has a collapse key on Android, and Apple Push Notification service has the apns-collapse-id header, which make the device show only the latest notification with that key instead of stacking several. Some providers also accept an idempotency key or message id for deduplication on their side. Passing the notification id as these keys means that even when a duplicate slips through our own check, the user sees one notification. The exact behaviour differs between providers and platforms, so check the provider's documentation.
6Reducing Redelivery at the Source
Deduplication handles duplicates; we also want fewer of them. Keep processing per poll short: lower max.poll.records, for example to 50, so a slow provider cannot push a poll past the interval, and put a timeout on each provider call. If calls are slow by nature, process them asynchronously with bounded concurrency but commit only completed offsets, or use a listener container with record-level acknowledgment so offsets are committed more often. Shut down gracefully on deployments so the consumer finishes and commits its current batch before leaving the group. With these, rebalances become rare and each one redelivers only a few records, which the deduplication store catches.
7Follow-up questions
Why not just switch to exactly-once semantics in Kafka?
Kafka's exactly-once transactions cover reading from and writing to Kafka topics atomically. Sending a push is a call to an external system outside that transaction, so Kafka cannot make it exactly once. For external side effects, idempotent processing, a deduplication store plus provider keys, is the practical way to get the effect of exactly once.
How long should deduplication records be kept?
At least as long as a duplicate can arrive: the maximum redelivery window plus upstream retry windows, which is usually minutes to hours. Keeping them for 7 days, matching typical topic retention, covers replays as well. With Redis we set an expiry; with a database table we delete old rows in a scheduled job or use time-based partitions.
8Conclusion
In this answer, we traced duplicate pushes to Kafka's at-least-once delivery. We checked the consumer for rebalances and polls that exceed max.poll.interval.ms, then the producer and upstream services for repeated events. We fixed it by deduplicating on a stable notification id before sending and recording each send, passing collapse or idempotency keys to the push provider, and keeping processing per poll short with more frequent commits so fewer records are redelivered.
Open with
Since the worker consumes from Kafka, which is at-least-once, I would first find out whether the same record was processed three times or whether three records were produced.
Then, if they want more
On the consumer side, I would check the logs and metrics for rebalances and for processing that exceeds max.poll.interval.ms. A classic cause is a slow push provider: with 500 records per poll and slow calls, one poll takes longer than five minutes, Kafka removes the consumer from the group, and the next owner reprocesses everything since the last committed offset.
Rolling deployments without graceful shutdown cause the same thing. If the consumer is healthy, I would look at the actual records for the duplicate pushes; if there are three distinct records, the cause is producer retries or, more often, an upstream service emitting the event more than once. The fix has layers.
In the worker, I would deduplicate on a stable notification id, claiming it in a table with a unique key or in Redis before sending and marking it sent afterwards, so a redelivered record is skipped.
I would pass that id as the collapse or idempotency key to FCM or APNs, so even a duplicate that slips through shows once on the device. And I would reduce redelivery itself by lowering max.poll.records, adding timeouts on provider calls, committing offsets more often and shutting down gracefully, so rebalances are rare and redeliver only a few records.
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 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 "Users report receiving the same push notification three times. The notification worker...": https://scrivio-interview-library.netlify.app/architecture/backend-system-design/dc23873ce9/