At-least-once message delivery: make duplicate processing safe
At-least-once delivery retries messages to avoid losing them, while accepting that the same message may arrive more than once. A consumer processes a message and then acknowledges it; if a failure occurs before the acknowledgement, the broker may deliver it again. This does not mean a business effect happens exactly once: consumers must tolerate repeated work.
At-least-once delivery retries messages to avoid losing them, while accepting that the same message may arrive more than once. A consumer processes a message and then acknowledges it; if a failure occurs before the acknowledgement, the broker may deliver it again. This does not mean a business effect happens exactly once: consumers must tolerate repeated work.
Delivery guarantees can apply to separate stages: producer-to-broker persistence and broker-to-consumer processing. Product settings and terms differ. This guide explains the concept using documented behavior from Amazon SQS standard queues, RabbitMQ, and Apache Kafka; their settings are not interchangeable.
Why does a message return?
Redelivery happens when a system cannot know whether work completed. A consumer may finish a business action, then lose its connection before sending an ACK. The broker has no confirmation and may retry. Similarly, a producer may retry after losing the broker's publish confirmation even though the message was stored, creating a duplicate.
| Point of failure | What may have happened | At-least-once consequence |
|---|---|---|
| Producer gets no publish confirmation | Broker stored the message, but the reply was lost | Retrying can publish a duplicate |
| Consumer acknowledges before processing | Consumer fails after ACK | The message is gone while the business work may be lost; avoid early ACK |
| Consumer fails after processing but before ACK | Business effect is saved, ACK is missing | Redelivery can repeat the effect |
| Failure between saving output and ACK | External write succeeded, confirmation did not | Redelivery tries to write the same result again |
Broker delivery and durable business effects are separate facts. An ACK usually transfers responsibility between consumer and broker; it does not atomically include a database update, payment, or other external side effect.
Make consumers safe to rerun
Idempotency is a common approach: processing the same input repeatedly produces the same final business state as processing it once. Include a stable event ID or business key, then atomically record that the consumer handled it with the business change.
For example, when applying an “order paid” event for order-8472, insert a unique (consumer, event_id) record and update the order in one database transaction. If the record already exists, treat the delivery as a duplicate and skip the update. The uniqueness constraint also handles two consumers racing on the same event. Saving a “processed” marker separately from the business change can reintroduce loss or duplication during a crash.
External calls usually cannot join the database transaction. If a payment API supports an idempotency key, send a stable key and record the outcome. For effects such as email that may be sent twice, persist intent and status and check the provider's deduplication support and recovery behavior. Keep idempotency records for at least as long as retries can occur.
Confirm only after the effect is safe
A consumer should acknowledge after its business effect is safely applied. ACK first and save later can lose work if a crash occurs in between. Save first and crash before ACK can cause duplicate delivery, so the write must be idempotent.
Products implement this differently:
**Amazon SQS standard queues:** a received message is hidden during the visibility timeout and removed with `DeleteMessage` after successful processing. Rare duplicate receives remain possible under at-least-once delivery; the visibility timeout alone cannot eliminate them.
**RabbitMQ:** enable consumer acknowledgements and ACK after completing the work. Unacknowledged messages can be redelivered after connection failures or consumer restarts. Publisher confirms cover a separate publish stage; retransmitting after an uncertain confirmation can also duplicate messages.
**Apache Kafka 4.4:** for at-least-once consumption, process a record and then commit its offset. A crash after processing but before the commit can make a new consumer read the record again. Committing before processing can skip a record after a crash. Kafka transactions can atomically combine input offsets with output records in Kafka; external stores must cooperate for equivalent guarantees.
When reviewing a design, record when confirmation occurs, which component retries, how messages are retained or removed, and where external effects fall outside an atomic transaction. Asking only “Do we use ACK?” misses these boundaries.
What to observe in production
Log event IDs, receive attempts or redelivery indicators when available, processing outcomes, and ACK/offset timing in structured form. Avoid logging full message bodies or secrets. Monitor redelivery counts, failures, DLQ arrivals, unacknowledged or in-flight messages, and the age of the oldest message. Identifiers help trace duplicates but should not contain personal or credential data.
In a test environment, exercise two failure windows: stop the consumer immediately after saving the business result but before ACK/offset commit, then confirm redelivery; and stop it before completing the work, then confirm the effect was not applied. In both cases verify that the final business outcome is applied once and recovery completes. This is a suggested procedure, not a claim that a test was run.
When to choose it
At-least-once can be practical when message loss is more costly than duplicate handling. It requires consumer idempotency or deduplication and a clear atomicity boundary. If an effect crosses external systems and duplicates are costly, evaluate those systems' idempotency support, transactions, or compensating business actions. Do not assume that an “exactly once” label guarantees one end-to-end business effect.
Sources and scope
Amazon SQS Developer Guide, “Amazon SQS at-least-once delivery”: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/standard-queues-at-least-once-delivery.html
RabbitMQ 4.4, “Reliability Guide”: https://www.rabbitmq.com/docs/reliability
Apache Kafka 4.4, “Design — Message Delivery Semantics”: https://kafka.apache.org/44/design/design/
Product statements are limited to the cited official documentation. Idempotency and failure-window analysis are design guidance connecting those behaviors to business data.