At most once, at least once or exactly once: what a message promise really means.
Delivery semantics tell you how many times a message will be delivered when things go wrong. There are three promises:
Networks drop packets and machines crash. So after you send a message, you may not know if it arrived. Did the message get lost, or did only the reply get lost? The delivery promise decides what the system does next.
At most once: you throw a letter in a mailbox. If it is lost, you never know and you do not send another.
At least once: you send the parcel and wait for a signed receipt. No receipt in a week? You send another. Your friend may now get two parcels.
Exactly once: same as above, but each parcel has a number. Your friend’s home keeps a list and refuses parcel #42 the second time.
| Use case | Usually pick | Why |
|---|---|---|
| Metrics, logs, “likes” count | At most once | Losing one sample is fine. Speed matters. |
| Emails, notifications, background jobs | At least once | Better a rare duplicate than a lost email. Often made idempotent. |
| Payments, orders, inventory | At least once + idempotent consumer | Must happen once, and must not be lost. |
| Stream processing with transactions | “Exactly once” features | Some systems offer it inside their own boundary. |
| Not idempotent | Idempotent version |
|---|---|
| balance = balance + 100 | Insert payment id 42 once (unique key), then add 100 |
| Send a new email each time | Send only if “email for order 17” is not marked sent |
| INSERT a row | Upsert (insert or update) by a unique key |
| Term | Meaning in easy words |
|---|---|
| Ack | A reply saying the message was received or handled |
| Retry | Sending again after no ack or a failure |
| At most once | Delivered zero or one time |
| At least once | Delivered one or more times |
| Exactly once | The effect happens one time (usually at-least-once plus dedupe) |
| Idempotent | Repeating it gives the same result as doing it once |
| Deduplication | Spotting and dropping repeated messages |
| Message id | A unique label for a message |
| Backoff | Waiting longer after each retry |
| Transaction | A group of steps that all happen or none happen |
| Promise | We gain | We lose |
|---|---|---|
| At most once | Speed, no duplicates | May lose messages |
| At least once | No loss | May get duplicates, need idempotency |
| Exactly once (effect) | Safe results | Extra work, state and latency |