Quick revision
The short answer
At-most-once means a message is never processed twice but may be lost; at-least-once means it is never lost but may be processed twice; exactly-once processing exists only inside a closed system or when the effect is idempotent. What decides between the first two is when the consumer acknowledges: acknowledge before the work for at-most-once, after the work for at-least-once. In Kafka that is the offset commit, in RabbitMQ the ack (automatic acknowledgement is at-most-once), and in SQS the DeleteMessage call.
What to remember
In this answer, we saw that the delivery guarantee depends on when the consumer acknowledges relative to doing the work. Acknowledging first gives at-most-once and acknowledging after gives at-least-once. In Kafka the acknowledgement is the offset commit, and auto-commit with asynchronous processing silently becomes at-most-once; in RabbitMQ it is the ack, with automatic acknowledgement meaning at-most-once; in SQS it is DeleteMessage within the visibility timeout. Exactly-once holds only within a closed system like Kafka transactions, and elsewhere we get it effectively through at-least-once delivery plus idempotent processing.
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.
At-most-once means a message is never processed twice but may be lost; at-least-once means it is never lost but may be processed twice; exactly-once processing exists only inside a closed system or when the effect is idempotent. What decides between the first two is when the consumer acknowledges: acknowledge before the work for at-most-once, after the work for at-least-once. In Kafka that is the offset commit, in RabbitMQ the ack (automatic acknowledgement is at-most-once), and in SQS the DeleteMessage call.
Why this question is asked
Every messaging system advertises a delivery guarantee, but the guarantee our application really gets is decided by a few lines of our own consumer code. Interviewers ask this because many teams believe they have at-least-once delivery while their consumer quietly loses messages, or believe they have exactly-once while they process duplicates. In this answer, we will define the three semantics in terms of a crash, then look at where the acknowledgement goes in Kafka, RabbitMQ and SQS, and finally see what exactly-once really means in practice.
1The Three Semantics, Explained With a Crash
A consumer does two things for each message: it does the work (writes to a database, sends an email) and it acknowledges the message, telling the broker it does not need to deliver it again. The semantics are simply about what happens if the consumer crashes between those two steps.
If we acknowledge first and then do the work, a crash in between means the broker thinks the message is done, but the work never happened. The message is lost, and it is never processed twice. That is at-most-once. If we do the work first and acknowledge afterwards, a crash in between means the work happened but the broker never heard about it, so it delivers the message again. Nothing is lost, but the work may run twice. That is at-least-once. Exactly-once would mean the work and the acknowledgement happen together, atomically, which is only possible when both live in the same system.
| Order of steps | Crash in between | Result |
|---|---|---|
| ack, then process | message marked done, work lost | at-most-once |
| process, then ack | work done, message redelivered | at-least-once |
| process and ack atomically | both or neither | exactly-once (closed system) |
2Kafka: The Offset Commit Is the Acknowledgement
A Kafka consumer does not acknowledge individual messages. It commits an offset per partition, meaning "I have handled everything before this position". After a crash or rebalance, the new owner of the partition starts from the last committed offset. So the question is whether the commit happens before or after processing.
Auto-commit deserves a warning. With enable.auto.commit=true, the consumer commits the positions from earlier polls on a timer during later poll() calls. If we process synchronously inside the poll loop, that is effectively at-least-once. But if we hand records to another thread pool and return to poll() immediately, auto-commit can commit offsets for records that are still being processed, and a crash loses them: at-most-once without anybody choosing it. In Spring Kafka, the listener container commits for us after the listener returns, according to its AckMode (BATCH by default, or RECORD), which gives at-least-once as long as the listener does its work synchronously.
3RabbitMQ: Automatic Versus Manual Acknowledgement
RabbitMQ acknowledges individual messages. With automatic acknowledgement, the broker considers a message delivered as soon as it has sent it to the consumer, so a consumer crash loses it: at-most-once. With manual acknowledgement, the consumer calls basicAck after processing. Unacknowledged messages are requeued and redelivered when the channel or connection closes, so a crash leads to redelivery: at-least-once.
In Spring AMQP, AcknowledgeMode.NONE corresponds to automatic acknowledgement at the broker (at-most-once), while the default AcknowledgeMode.AUTO makes the container ack after the listener returns normally and reject on an exception, which is at-least-once. AcknowledgeMode.MANUAL leaves the ack to our code.
4SQS: Visibility Timeout and DeleteMessage
SQS works differently again. When a consumer receives a message, SQS does not remove it; it hides it for the visibility timeout (30 seconds by default). If the consumer deletes the message within that time, it is gone. If not, it becomes visible again and another consumer receives it. So DeleteMessage is the acknowledgement. Deleting before processing gives at-most-once. Processing and then deleting gives at-least-once, with one extra trap: if processing takes longer than the visibility timeout, the message reappears while we are still working on it, and a second consumer processes it too. We either set the timeout longer than the slowest processing or extend it with ChangeMessageVisibility while we work.
5What Exactly-Once Really Means
Exactly-once is real in one situation: when the input, the output and the acknowledgement are all in one system that can commit them together. Kafka transactions do this for a read-process-write loop within Kafka. The consumed offsets and the produced records are committed in one transaction, and consumers reading with isolation.level=read_committed never see aborted output. Kafka Streams uses this when processing.guarantee is exactly_once_v2.
As soon as the work touches the outside world, an email, a payment API, a database in another system, that atomicity is gone. Then the honest description is at-least-once delivery plus deduplication or an idempotent effect: we may receive a message twice, but processing it the second time changes nothing, for example an upsert by event id, or a processed-ids table updated in the same database transaction as the work. People often call this effectively-once. It is what most production systems that claim exactly-once actually do.
6Follow-up questions
Which semantics should a payment consumer use?
At-least-once with an idempotent effect. Losing a payment event is unacceptable, so we acknowledge after processing, and we make processing safe to repeat with a unique constraint on the payment or event id, so a redelivered message finds the work already done.
Can at-most-once ever be the right choice?
Yes, for data where a rare loss is cheaper than a duplicate or than the cost of tracking, such as high-volume metrics or telemetry samples, or notifications that are useless if late. It is a legitimate choice as long as it is made on purpose.
Does Kafka's idempotent producer give exactly-once end to end?
No. It removes duplicates caused by the producer's own retries when writing to a partition. Consumers can still process records twice after a crash, and an application can still send the same event twice; those need transactions within Kafka or idempotent processing.
7Conclusion
In this answer, we saw that the delivery guarantee depends on when the consumer acknowledges relative to doing the work. Acknowledging first gives at-most-once and acknowledging after gives at-least-once. In Kafka the acknowledgement is the offset commit, and auto-commit with asynchronous processing silently becomes at-most-once; in RabbitMQ it is the ack, with automatic acknowledgement meaning at-most-once; in SQS it is DeleteMessage within the visibility timeout. Exactly-once holds only within a closed system like Kafka transactions, and elsewhere we get it effectively through at-least-once delivery plus idempotent processing.
Open with
The three semantics are really about what happens if the consumer crashes between doing the work and acknowledging the message. If I acknowledge first and then process, a crash loses the message but it is never processed twice: at-most-once.
Then, if they want more
If I process first and then acknowledge, a crash causes redelivery, so nothing is lost but I may process twice: at-least-once. Exactly-once needs the work and the acknowledgement to commit atomically, which only happens inside one system. In Kafka the acknowledgement is the offset commit.
Committing before processing gives at-most-once, and so does auto-commit when I hand records to another thread, because offsets can be committed for work still in progress. Committing after processing, which is what Spring Kafka's container does after the listener returns, gives at-least-once.
In RabbitMQ, automatic acknowledgement counts the message as delivered when it is sent, so that is at-most-once; a manual basicAck after processing gives at-least-once, and unacked messages are redelivered when the channel closes.
In SQS the message is only hidden for the visibility timeout; deleting after processing is at-least-once, deleting before is at-most-once, and I have to keep processing shorter than the timeout or extend it. Real exactly-once exists in closed systems, like Kafka transactions for read-process-write; otherwise it is at-least-once plus deduplication or idempotent effects, often called effectively-once.
About this answer
- Last updated
- 13 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 "Explain the three semantics, and show where the acknowledgement must happen to get...": https://scrivio-interview-library.netlify.app/architecture/distributed-systems/620f230313/