Quick revision
The short answer
We find the lossy hop by counting events per time window at every stage (produced, in Kafka, processed, loaded) and comparing event ids between adjacent stages. The usual culprits are producers with acks=1 or fire-and-forget sends, sends outside the database transaction, auto-commit with asynchronous processing, error handlers that log and skip, and loaders that drop bad records; we fix each with outboxes, acks=all, retries and dead-letter topics, commit-after-processing and quarantine, then add a continuous reconciliation job that compares counts and ids per window and alerts within minutes.
What to remember
In this answer, we treated a 0.02 percent loss as a counting problem. Per-window counts at every hop find where events disappear, and id comparisons show which ones. We listed the usual hidden at-most-once points, acks=1 and ignored send results, sends outside an outbox, auto-commit with async work, log-and-skip handlers and dropping loaders, and fixed them with outboxes, acks=all, commit-after-processing, dead-letter topics and quarantine. A reconciliation job every 5 minutes then detects and replays losses, and fault injection proves each stage's contract.
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.
We find the lossy hop by counting events per time window at every stage (produced, in Kafka, processed, loaded) and comparing event ids between adjacent stages. The usual culprits are producers with acks=1 or fire-and-forget sends, sends outside the database transaction, auto-commit with asynchronous processing, error handlers that log and skip, and loaders that drop bad records; we fix each with outboxes, acks=all, retries and dead-letter topics, commit-after-processing and quarantine, then add a continuous reconciliation job that compares counts and ids per window and alerts within minutes.
Why this question is asked
A loss rate of 0.02 percent sounds tiny until we remember these are payment events: at 50 million events a day it is 10,000 missing payments in the warehouse every day, and finance cannot close the books. The hardest part is that every team believes its own stage is at-least-once, so nobody knows where to look. Interviewers ask this to see whether we can investigate systematically across teams and design controls that catch losses quickly. In this answer, we will locate the losing hop by counting, go through the typical hidden at-most-once points and their fixes, and then build continuous reconciliation and testing.
1Why At-Least-Once Is Only as Strong as the Weakest Hop
At-least-once means that a crash or error leads to a retry, never to a loss. A pipeline is at-least-once end to end only if every hop is: the service that produces the event, the Kafka write, the stream processor, and the loader that writes to the warehouse. A single hop that acknowledges before its work is done, or swallows an error, makes the whole pipeline at-most-once for the events that happen to fail there. With 30 producing services, it only takes one of them to explain the gap.
2Finding the Hop by Counting
We do not start by reading code in 30 repositories. We start by measuring. For a fixed time window, say each 5 minutes of event time, we count events at every hop: events produced per service (from their outbox tables or producer success metrics), records per partition in Kafka (from offsets), records consumed and emitted by the stream job, and rows loaded into the warehouse. Where two adjacent counts differ, the loss is between them.
| Hop | Events | Difference |
|---|---|---|
| Outbox rows in 30 services | 174,012 | - |
| Records in Kafka topic | 174,012 | 0 |
| Processed by stream job | 174,012 | 0 |
| Emitted by stream job | 173,987 | -25 |
| Rows in warehouse | 173,977 | -10 |
Counts tell us where; event ids tell us which. For the window with a gap, we take the set of event ids on both sides of the hop and compute the difference. The missing ids then lead us straight to logs and error handlers for those exact events. Often a pattern appears quickly: all missing events come from one service, or have a null currency field, or arrived during a deploy.
3The Usual Hidden At-Most-Once Points
Experience shows the same handful of causes again and again. On the producer side, a send with acks=1 is acknowledged by the partition leader alone, and if the leader fails before the followers copy the record, it is gone. A fire-and-forget send, where the Future or callback result is ignored or only logged, loses the event whenever retries run out. And a send made after the database commit but outside any outbox loses the event if the service crashes between the two steps.
On the consumer side, auto-commit with asynchronous processing commits offsets before the work finishes. Error handlers that log and skip, a catch block that writes an error and moves on, are the most common at-most-once point of all, because everyone remembers to handle errors and few ask what happens to the record. Loaders that drop records failing schema validation lose data quietly too.
| Where | Hidden at-most-once | Fix |
|---|---|---|
| Producer | acks=1 or ignoring send() result | acks=all, idempotence on, fail on send error |
| Producer | send after commit, no outbox | transactional outbox and relay |
| Consumer | auto-commit with async work | commit only after processing |
| Consumer | catch, log and skip | retries, then a dead-letter topic |
| Loader | drop invalid records | quarantine table and alert |
4Fixing Each Hop
Producers move to the transactional outbox: the event is written in the same database transaction as the payment, and a relay publishes it with acks=all and idempotence enabled (both are the defaults for the Java producer since Kafka 3.0, but older code or explicit configuration often overrides them, so check). The relay only marks an outbox row as sent after the broker acknowledges it.
Consumers commit offsets only after successful processing. Errors are retried a few times with backoff, and records that still fail go to a dead-letter topic with the error attached, never into a log line alone. In Spring Kafka, a DefaultErrorHandler with a DeadLetterPublishingRecoverer does exactly this. The loader writes invalid records to a quarantine table with the reason, so that finance can see them and they can be fixed and reloaded.
5Detecting Losses Within Minutes
Fixes reduce losses, but only continuous reconciliation proves there are none. A reconciliation job runs every 5 minutes on the window that closed 15 minutes ago, giving late events time to arrive. It compares counts per window between the sources (outbox tables or producer metrics) and the warehouse, and when counts differ it compares id sets to list the missing events. A gap raises an alert to the owning team of the hop where the ids disappeared, and the job can trigger a replay of those ids from the source, the outbox or Kafka within its retention.
Finally, the guarantee becomes part of each service's contract. Each stage documents what it promises, at-least-once with idempotent writes, and proves it with fault injection before production: killing consumers mid-batch, failing a broker, restarting the loader, then checking that reconciliation reports zero missing ids.
- Pick window closed 15 min agolate events have arrived
- Count per hop for the windowoutbox, Kafka, stream job, warehouse
- Counts equal everywhere?YesRecord success, doneNoDiff event ids at the gap
- Alert owning team with missing idsnames the hop and the events
- Replay missing ids from sourceoutbox or Kafka within retention
5 steps in order. Play them, or step through them one at a time.
6Follow-up questions
Why not just reconcile the warehouse against the payment databases at the end of the day?
Because that finds losses up to a day late and gives no clue where they happened. Per-window counts at every hop catch a loss within minutes and point at the hop, which turns a finance investigation into an engineering alert.
What if counts match but the ids differ?
Then one hop is losing events while another is duplicating them, and the totals hide both. That is why the job compares id sets when anything looks unusual, and periodically even when counts match, for example by comparing a hash of sorted ids per window.
Do we need exactly-once anywhere in this pipeline?
No. At-least-once at every hop plus an idempotent warehouse load, an upsert keyed by event id, gives correct results. Duplicates are cheap to remove; losses are expensive to find.
7Conclusion
In this answer, we treated a 0.02 percent loss as a counting problem. Per-window counts at every hop find where events disappear, and id comparisons show which ones. We listed the usual hidden at-most-once points, acks=1 and ignored send results, sends outside an outbox, auto-commit with async work, log-and-skip handlers and dropping loaders, and fixed them with outboxes, acks=all, commit-after-processing, dead-letter topics and quarantine. A reconciliation job every 5 minutes then detects and replays losses, and fault injection proves each stage's contract.
Open with
I'd treat it as a counting problem rather than read thirty codebases. For each five-minute window of event time I'd count events at every hop: produced per service from their outbox tables or producer metrics, records in Kafka from partition offsets, records in and out of the stream job, and rows in the warehouse.
Then, if they want more
Where adjacent counts differ, that's the lossy hop, and comparing event id sets for that window gives me the exact missing events to trace in logs.
Typically the at-most-once behaviour is one of a few things: producers with acks=1 or fire-and-forget sends where failures are only logged; events sent after the database commit without an outbox, so a crash loses them; consumers using auto-commit while processing asynchronously; error handlers that log and skip; and loaders that drop invalid records.
The fixes are a transactional outbox with acks=all and idempotence, committing offsets only after processing, retries and then a dead-letter topic instead of skipping, and a quarantine table instead of dropping.
For detection within minutes I'd run a reconciliation job every five minutes on the window that closed fifteen minutes earlier, comparing counts and, when needed, id sets between source and warehouse, alerting the owning team and replaying missing ids from the outbox or Kafka.
Finally I'd make the delivery guarantee part of each service's contract and test it with fault injection, killing consumers and brokers in staging and checking reconciliation shows zero gaps.
About this answer
- Last updated
- 13 November 2026
- Versions it names
- Kafka 3.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 do you find where at-most-once behaviour crept in, and which controls do you add so...": https://scrivio-interview-library.netlify.app/architecture/distributed-systems/69dfeb4903/