At-least-once delivery

On this page 7

At-least-once delivery is a message delivery guarantee under which every message or event is delivered to its consumer one or more times, so that nothing is lost even when components fail, but the same message may be processed repeatedly. In streaming data systems, it is the most common default guarantee offered by message brokers and stream processors, because it protects completeness at a modest cost.

The guarantee rests on a simple rule: a message is considered done only after the consumer explicitly acknowledges it. Until that acknowledgment arrives, the producer or broker keeps the right to resend. The price of this safety is the possibility of duplicates, which downstream logic must tolerate or remove.

How at-least-once delivery prevents data loss

At-least-once delivery works by combining durable storage, acknowledgments and retries. A producer sends a record and waits for the broker to confirm that the record is persisted. If no confirmation arrives within a timeout, the producer sends the record again. On the consuming side, the consumer processes the record first and commits its position or acknowledgment afterward.

The ordering of the last two steps is the core of the guarantee. If a consumer crashes after processing but before committing, it restarts from the last committed position and processes the same records again. No record is skipped, yet some records are handled twice. Reversing the order, committing first and processing second, gives at-most-once behavior instead.

The table below shows where duplicates arise along a typical event path.

Failure pointWhat happensResulting duplicate
Lost producer acknowledgmentBroker stored the record, but the reply was lostProducer retry writes a second copy
Consumer crash before commitRecords processed, offset not savedBatch is reprocessed after restart
Rebalance in a consumer groupPartition moves to another consumerUncommitted records are read again
Visibility timeout expirySlow processing exceeds the leaseQueue redelivers to another worker
Where duplicates originate

Delivery guarantees compared

At-least-once delivery sits between two other guarantees, and the choice among them is a trade-off between completeness, duplication and cost. Each guarantee describes what happens under failure, not under normal operation, when all three behave identically.

GuaranteeData lossDuplicatesTypical cost
At-most-oncePossibleNoneLowest latency and overhead
At-least-onceNonePossibleRetries and idempotent consumers
Exactly-once semanticsNoneNone in effectTransactions, coordination and higher latency
Three delivery guarantees side by side

A frequent misconception is that exactly-once semantics removes retries. In practice, exactly-once is usually at-least-once delivery plus deduplication or transactional commits, so that repeated deliveries have no repeated effect. Exactly-once guarantees also tend to hold only inside one system boundary, such as a broker and a stream processor; side effects in external databases or APIs still need their own protection.

Making consumers safe for duplicates

Because duplicates are expected, the decisive design property under at-least-once delivery is idempotent processing: handling the same message twice must leave the system in the same state as handling it once. Teams that design for idempotency early rarely need stronger guarantees.

The following table lists the standard techniques and when each fits.

TechniqueHow it worksBest fit
Idempotency keyStore each processed message ID and skip repeatsPayments, orders and notifications
Upsert by natural keyInsert or overwrite the same rowState tables and dimension updates
Conditional writeApply only if the version or sequence is newerCounters and concurrent updates
Windowed deduplicationRemove repeated IDs within a time windowHigh-volume event streams
Transactional outboxWrite state and output in one transactionServices publishing derived events
Techniques for duplicate-safe consumers

Some operations are naturally idempotent, such as setting a status to shipped, while others are not, such as incrementing a balance or sending an email. Non-idempotent operations require an explicit deduplication store, and its retention period must exceed the longest plausible redelivery delay.

Configuring the guarantee in common platforms

Most streaming platforms provide at-least-once delivery when producers retry and consumers commit after processing. In Kafka, this means producer acknowledgments from all in-sync replicas, retries enabled, and manual or carefully timed offset commits. Apache Pulsar uses individual or cumulative acknowledgments, while Amazon Kinesis consumers checkpoint their position after processing each batch.

Several configuration choices quietly change the effective guarantee, and they deserve review in every pipeline.

SettingSafe choiceRisk when misconfigured
Auto-commit of offsetsDisable or commit after processingRecords skipped after a crash
Producer acknowledgmentsWait for all replicasLoss when a leader fails
Retry limitHigh, with backoffSilent drops after a few failures
Dead-letter queueRoute poison messages asideEndless redelivery blocks the partition
Settings that affect the guarantee

Retries can also reorder messages when several requests are in flight at once, so pipelines that depend on order should limit concurrent requests or rely on idempotent producers that preserve sequence.

Limitations and common mistakes

The guarantee covers delivery, not correct outcomes. A pipeline can deliver every event and still produce wrong aggregates if duplicates inflate counts or sums. Analysts often notice the problem only when totals disagree with a source system.

  • Assuming duplicates are rare: during outages and rebalances, whole batches of thousands of records can repeat.
  • Deduplicating on payload content: two legitimate identical events, such as two equal purchases, get merged wrongly.
  • Short deduplication retention: a replay from hours earlier passes the check unnoticed.
  • Ignoring external side effects: emails, webhooks and charges repeat even when the database write is idempotent.
  • Committing before processing: the pipeline silently becomes at-most-once.

The simple explanation

Think of a courier who must get a signature for every parcel. If the courier is not sure the signature was recorded, the courier comes back with the same parcel. Nothing ever goes missing, but sometimes a parcel arrives twice.

At-least-once delivery works the same way for data. The system keeps resending until it is certain each message arrived. The receiving side simply has to recognize a parcel it already has and set the copy aside.

How it is used in practice

An online ticketing platform publishes an event for every completed booking to a topic with 12 partitions. A consumer service reads these events, writes each booking to the reporting database and sends a confirmation email. The service uses at-least-once delivery and commits offsets only after both steps succeed.

During a deployment, a consumer instance is stopped after processing about 800 events but before its next commit. The replacement instance rereads those 800 events. Because the database write is an upsert keyed by booking ID, the reporting table stays correct. The email step checks a table of sent booking IDs retained for seven days, so no customer receives a second confirmation.

The team accepts the occasional reprocessing cost in exchange for a pipeline that never loses a booking, which matters far more for revenue reports than a few seconds of extra work.