Skip to content
WebsiteHosting.com

concept Backend & software

Duplicate delivery and the exactly-once illusion

A broker acknowledgment does not prove a change happened exactly once. Follow two deliveries of the same request and see why a crash between applying a credit and recording its key can leave two credits instead of one.

Latest recorded source check · P0130

What it means

At-least-once delivery allows the same message to arrive more than once. A broker acknowledgment does not, by itself, prove that the message produced exactly one change in another system. To make that claim, you need to know what happens where the change is made when the same request arrives again.

Suppose a message asks a consumer to add one credit to a balance. Call the operation credit-17: every delivery with that key is a request for the same credit, not a request for another one. There are two counts to keep apart: how many times the consumer receives the request, and how many credits it actually applies.

Try it

Simulation. Start with 2 delivery attempts for the same key, atomic effect deduplication, and scenario evidence provided. The result is 2 deliveries, 1 effect. On the first delivery, the consumer applies the credit and records credit-17 together. On the second, it finds the record and does not add a credit. The crash setting is yes, but it is not evaluated: there is no separate ledger write to crash before.

Duplicate delivery and the exactly-once illusion

Separate at-least-once delivery, deduplication and effect execution

Simulation
Modeled outcome: Once

Exactly one effect is counted. A single delivery needs no suppression; with multiple deliveries the stipulated ledger policy may suppress repeated effects.

Duplicate delivery and the exactly-once illusion: synthetic scenario inputs
Replaces all inputs with the documented starting example and the indicated change. Reset restores the starting example.
Delivery count versus durable effect count

Consumer policy

  1. Ledgeratomic
  2. Separate-record crashNot evaluated
  3. Reason for countAtomic effect + record
  4. Duplicate effectsNone in this fixture
Delivery attempts2 count
Durable effects1 count

One effect can result from one delivery without any suppression. The modeled crash gap matters only for the separate ledger branch.

Evaluated inputs

Required scenario evidence
provided
Effect deduplication
atomic
Delivery attempts for same key
2 count

Not evaluated: Crash between effect and separate ledger

One idempotency key and successful retries, one crash before separate ledger if selected; no live queue or external effect.

About this model

The controls set only a local, bounded scenario. The computed branch is not a verdict about a live system. Inputs listed as not evaluated did not participate in this branch after validation.

Reset restores the original inputs. It does not change the open or closed state of help or FAQ answers.

Change only Effect deduplication to non-atomic. The delivery count stays at 2, but the effect count rises to 2. Now the crash setting matters: the first credit survives the crash; the record that would have stopped the second credit does not exist yet. Keep non-atomic and change the crash setting to no. The result returns to 1 effect because the record is in place before the retry.

Select none to compare: both deliveries apply a credit, with no ledger to consult. If you select missing for required scenario evidence, the outcome is unknown, not zero effects. Delivery attempts must be a whole number from 1 to 10; a missing or invalid count gives no result. Reset restores the initial two-delivery, atomic example. None of these choices sends a message or changes a balance.

What survives the crash

A ledger here is a durable record of which operations have taken effect. The critical question is what the retry will find in that ledger. Follow credit-17 through the non-atomic example with the crash selected:

MomentCredits applied so farDurable record for credit-17
Before the first delivery0Absent
After the first credit, at the crash1Absent
When the second delivery checks the ledger1Still absent
After the second delivery finishes2Present

The second delivery carries the right key. The problem is that the consumer cannot tell from the absent record whether the first attempt did nothing or already applied the credit. Even the final ledger, with one key in it, does not establish that only one credit was applied.

In the atomic example the credit and its key become durable as one operation: the retry cannot encounter the middle state of credit applied, key absent. The non-atomic example without a crash also ends with one credit, but for a different reason: nothing interrupted the two writes in that history. One successful run is not evidence that the gap is closed.

With only one delivery and no ledger, the count is also one. In that case there was no repeat to suppress. The result label and the two counts must be read with the ledger premise: a single observation of one effect is not evidence that the next delivery will be recognized.

In practice

When a service promises “exactly once,” ask what the promise covers. For example, Kafka 4.3 describes transactions that can commit a consumer's position together with output written to Kafka topics. That is a defined boundary. A balance change in an external system is not automatically part of that transaction.

To investigate a repeated delivery, trace one operation key across the delivery history and the destination's durable records. Look for the change itself, not just the acknowledgment. Determine whether the destination enforces the key for that particular operation, whether the change could survive without its record, and whether the record would still be available when a late duplicate arrived. If the first attempt's response is missing, do not assume it is safe to repeat the operation just to see what happens.

This simulation covers one key, successful retries, and at most one crash between an effect and a separate ledger write. It does not inspect a queue, test retention, or observe an external effect. Count deliveries at the broker and justify effects at the destination. If all you have is the acknowledgment, leave the external effect count unknown.

Frequently asked questions

Editorial questions based on the listed sources and explicitly labeled local examples.

Is duplicate delivery necessarily duplicate effect?

No. A correctly scoped durable deduplication or atomic effect mechanism can make repeated delivery yield one effect. Merely seeing an identical message ID is not sufficient.

Can a separate ledger leave a gap?

Yes. The effect may become durable before the deduplication record does. If the system fails in that interval, a repeated delivery may find no record and repeat the effect. Establish the atomic boundary rather than assuming a successful first effect was recorded.

Is an idempotency key enough?

Not on its own. The consumer must enforce the key in the relevant operation scope. If it has discarded the only record that a key was processed, that record cannot distinguish a later duplicate. Establish the required deduplication window and atomic effect policy.

Does a retry mean previous effect failed?

Not necessarily. A response can be lost after the effect became durable. Treat an uncertain outcome as uncertain; do not assume retry is harmless.

Sources & model boundaries

Primary references used for this explanation. The interactive example is an educational model, not a live check.

  1. Apache Kafka design: message delivery semantics

    delivery semantics. Atomic offsets and output topics can support scoped exactly-once processing; external outputs require coordination.

    Checked .

  2. AWS transactional outbox pattern

    Issues and considerations: duplicate delivery. Separate database and message writes can fail independently. Outbox relays can duplicate delivery; consumer deduplication and its retention scope need explicit treatment.

    Checked .

Report an issue. Include the article URL and ID, not passwords or access keys.