CONCEPT
What is at-least-once delivery?
At-least-once delivery means the broker keeps redelivering a message until the consumer acknowledges it. The message is never lost, but it can arrive more than once. So the consumer must tolerate duplicates, and exactly-once effects come from an idempotent consumer on top.
The problem it solves
A message can be delivered and processed but never acknowledged, because the consumer crashes before it replies or the reply is lost. The broker cannot tell "never arrived" from "arrived, ack lost". It has two choices: forget the message and risk losing it, or send it again and risk a duplicate. At-least-once picks the second.
How it works
The broker keeps the message until the consumer acknowledges it. If the acknowledgement never comes, it delivers the message again.
broker -> consumer message 42
consumer does the work, then crashes before the ack
broker no ack, so it delivers message 42 again
At-most-once is the opposite trade. The broker hands the message over and forgets it (automatic acknowledgement), so a crash mid-work loses the message, but nothing is ever duplicated.
"Exactly-once" is easy to promise and hard to deliver. In practice it means at-least-once delivery plus an idempotent consumer: the message may arrive twice, but the effect happens once. The usual tool is a stable id per logical event, recorded under a unique constraint in the same transaction as the effect. A retry then finds its own record and does nothing.
What it does not do
- It does not prevent duplicates. It trades them for no loss. Every consumer must handle seeing a message twice.
- It does not cover the sender's side. A producer that publishes and crashes before recording it will publish again. A transactional outbox gives at-least-once publishing, not exactly-once.
- It cannot make an outside action happen once. Sending an SMS or charging a card crosses a boundary the broker cannot see. The provider has to deduplicate, for example through an idempotency key.
Measured
In my sharding challenge, 100 writes were made whose reply was lost after the commit, so the API retried.
| Retry carries | Writes asked | Rows stored | Duplicates |
|---|---|---|---|
| the same request id | 100 | 100 | 0 |
| nothing, it starts over | 100 | 200 | 100 |
In the one message per action challenge, 2,000 actions went through workers killed 200 times at random, a database restart, and a provider that dropped requests and replies and repeated webhooks. Checked against the provider's own log, 2,000 of 2,000 actions had exactly one effect. Every retry was preceded by a lookup and reused the original key.
RUN IT YOURSELF
Challenge · Distributed Systems ChallengesOne message per action through a flaky providerGO DEEPER
Why Exactly-Once Processing Is Hard: RabbitMQ, Retries, and IdempotencyWhere RabbitMQ duplicates come from and how an outbox, deduplication keys and idempotent consumers protect database effects and external calls.When RabbitMQ Isn't Enough: Building Durable, Retryable JobsDatabase-backed jobs with atomic claiming, backoff, circuit breakers and an outbox, and what each piece does and does not guarantee.RELATED CONCEPTS
What is an idempotency key?What is the transactional outbox pattern?What is a fencing token?SOURCES
Get the next deep dive by email
New deep dives on how production systems really behave, from Kubernetes networking to PostgreSQL internals. About one email a month.
You will get one email to confirm. Unsubscribe from any email with one click. Your address is used for this newsletter and nothing else.
Written by Zeeshan Adil
I run systems like this for a living. If your team is fighting the same problem, or wants this as a talk, write to me.