Quick revision
The short answer
I would guide the organisation away from expecting exactly-once delivery and toward building exactly-once effects. Across independent systems, a sender can never be sure a message was received and acted on, so duplicates and reordering will happen; vendor features such as Kafka transactions give exactly-once only inside their own boundary. So every write path must tolerate duplicates and reordering through idempotency and deduplication, backed by periodic reconciliation, with these rules written into our API and event standards and audited first in financial and regulatory flows.
What to remember
In this answer, we set out the long-term view on duplicates and ordering. Exactly-once delivery across independent systems is not achievable, so we build exactly-once effects through idempotency, deduplication and versioning. Vendor features such as Kafka transactions are valuable but hold only within their boundary. We make every write path tolerate duplicates and reordering, reconcile important data periodically, put idempotency keys and event ids into our standards and libraries, and audit financial and regulatory flows first.
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 guide the organisation away from expecting exactly-once delivery and toward building exactly-once effects. Across independent systems, a sender can never be sure a message was received and acted on, so duplicates and reordering will happen; vendor features such as Kafka transactions give exactly-once only inside their own boundary. So every write path must tolerate duplicates and reordering through idempotency and deduplication, backed by periodic reconciliation, with these rules written into our API and event standards and audited first in financial and regulatory flows.
Background to this question
Exactly-once is one of the most attractive phrases in data engineering, and vendors use it in good faith about real features. The risk is that an organisation hears it as a guarantee for the whole business process and stops designing for duplicates. Then, years later, an incident shows customers charged twice or a regulatory report double-counted. A senior engineer asked this question is expected to set the long-term thinking: what is actually possible, what the features really promise, and which habits and standards make correctness last. In this answer, we will explain why exactly-once delivery is not achievable across systems, what vendor features do guarantee, how to design for duplicates and reordering, and how to turn that into organisational standards and audits.
1Why Exactly-Once Delivery Cannot Be Guaranteed Across Systems
Consider a service that sends a message to another service over a network. If no acknowledgement comes back, the sender cannot know which of three things happened: the message was lost, it arrived but the receiver crashed before acting, or it was processed and only the acknowledgement was lost. The sender has two choices. It can resend, and risk a duplicate, which gives at-least-once delivery. Or it can give up, and risk a loss, which gives at-most-once delivery. No protocol between independent systems removes this uncertainty, because the acknowledgement itself can be lost.
So exactly-once delivery, in the sense of a message being delivered and acted on precisely once across independent systems with independent failures, is not something we can buy. What we can build is exactly-once effects: we deliver at least once, and we make the receiver recognise and ignore the repeats. The business sees the effect once, which is what it actually cares about.
2What Vendor Features Really Promise
Vendor features are valuable, but each one holds within a boundary. Kafka's idempotent producer stops a producer's retries from writing duplicate records to a partition. Kafka transactions let a consume-process-produce application read from topics, write to topics and commit its consumer offsets atomically, so consumers that read with isolation.level=read_committed see each result once. Stream processors build on these to give exactly-once processing within Kafka.
The boundary is the edge of Kafka. When the processing step writes to PostgreSQL, calls a payment provider, sends an email or updates a search index, that side effect is outside the transaction. If the application crashes after the external call and before the Kafka commit, the input is processed again and the external call happens again. The same is true of other vendors' exactly-once claims: read what boundary they cover, and assume everything outside it is at-least-once.
- Business outcomecustomer charged once: needs our own idempotency
- External side effectsdatabase, payment API, email: at-least-once
- Kafka consume-transform-producetransactions: exactly-once inside Kafka
- Kafka producer to partitionidempotent producer: no duplicate records
4 layers, from the top down. Step through them one at a time.
Each layer's guarantee stops at its own boundary; the top layer is our responsibility.
3Design Every Write Path to Tolerate Duplicates and Reordering
The practical principle is simple to state: every consumer and every write endpoint must assume it will see the same message twice and messages in the wrong order. Duplicates are handled by idempotency, for example a unique constraint on a business key, a processed-message table written in the same transaction as the business change, or operations designed to set a state rather than apply a change. Reordering is handled by versions: each event carries a sequence number or version per entity, and a consumer ignores an event older than what it has already applied.
Even with all of that, mistakes and edge cases will slip through: a bug in one consumer, a manual replay of a topic, a partner who sends a file twice. So for important data we add periodic reconciliation, a job that compares two independent views of the truth, such as our payment records against the provider's settlement report or the ledger against account balances, and raises every difference. Reconciliation is how we find out that a guarantee we believed in did not hold, before a customer or an auditor does.
4Make Idempotency Part of the Standards
Good intentions in one team do not survive ten years and a hundred services. So we write the rules into the standards every team already follows. In the API standard, every non-safe operation that clients may retry accepts an idempotency key, and the service stores it with the result and returns that result on replays. In the event standard, every event has a unique id and an entity version in its envelope, and consumers are expected to deduplicate by id and order by version. Shared libraries implement both patterns so the correct way is also the easy way.
We also change how we talk about guarantees. Design reviews ask 'what happens if this message arrives twice, or late?' as a standard question, and architecture documents describe delivery as at-least-once with idempotent consumers rather than exactly-once. Language shapes what people build.
5Audit Financial and Regulatory Flows First
We cannot review every flow at once, so we start where duplicates cost the most: payments, refunds, ledgers, invoices, payroll and regulatory reporting. For each flow, the audit traces the path from the first request to the final record and asks three questions at every hop. Is there a stable key that identifies this operation? Is the duplicate check enforced atomically with the write? Is there a reconciliation that would catch a failure? Gaps go onto the owning team's roadmap with a deadline proportional to the risk.
For example, an audit might find that refunds are triggered from an event and call the payment provider with no idempotency key. The fix is cheap, because most payment providers accept an idempotency key on their API, but without the audit it would only be found after a customer was refunded twice.
6Follow-up questions
Is at-least-once with idempotency always better than at-most-once?
Not always. For metrics, logs or notifications where a lost message is cheap and a duplicate is annoying, at-most-once can be acceptable. For anything involving money, stock or legal records, losing a message is worse than receiving it twice, so at-least-once with idempotent consumers is the standard choice.
How do you handle an external API that offers no idempotency key?
We wrap it. Before calling it, we record the intent with our own key in our database; after the call, we record the outcome. On a retry, if the intent exists without an outcome, we first ask the external system whether the operation already happened, by looking it up with a reference we passed, before calling again. Reconciliation then covers the remaining uncertainty.
How would you explain this to a non-technical executive?
I would say that no system can promise a message is acted on exactly once, in the same way a phone call can drop just as the other person says yes. What we can promise is that acting on it twice has no extra effect, and that we check our records against independent ones regularly, so any mistake is found and corrected quickly.
7Conclusion
In this answer, we set out the long-term view on duplicates and ordering. Exactly-once delivery across independent systems is not achievable, so we build exactly-once effects through idempotency, deduplication and versioning. Vendor features such as Kafka transactions are valuable but hold only within their boundary. We make every write path tolerate duplicates and reordering, reconcile important data periodically, put idempotency keys and event ids into our standards and libraries, and audit financial and regulatory flows first.
Open with
I would start by resetting the expectation. Between independent systems, a sender that gets no acknowledgement cannot tell whether the message was lost or only the acknowledgement was, so it must either resend and risk a duplicate, or give up and risk a loss.
Then, if they want more
That means exactly-once delivery across systems is not something any vendor can sell us. What we can build is exactly-once effects: deliver at least once, and make every receiver recognise repeats. Vendor features help within their boundary.
Kafka's idempotent producer and transactions give exactly-once processing inside Kafka, but a database write, a payment call or an email outside that transaction can still happen twice.
So my guidance is that every write path tolerates duplicates and reordering: unique business keys or processed-message tables in the same transaction, state-based operations where possible, and entity versions so a late event cannot overwrite newer state. For critical data I add periodic reconciliation against an independent source, because that is how we find the cases our design missed.
To make it last, I would put idempotency keys into the API standard and event ids and versions into the event envelope, back both with shared libraries, and make 'what if this arrives twice or late' a standard design-review question. And I would start with an audit of payments, refunds, ledgers and regulatory reports.
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 Data JPA reference, Hibernate ORM documentation, Spring Framework reference, Transaction management
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 "Exactly-once processing is often promised by vendors. How would you guide an...": https://scrivio-interview-library.netlify.app/databases/locking-and-concurrency-control/57f3aead44/