Skip to content
PHP2Shell: The PHP Bug
Akshay Thakare

Exactly-Once Is a Myth; Idempotency Is the Answer

Why distributed systems deliver at-least-once, what 'exactly-once' really means in Kafka and Spark, and how idempotent writes give you correct results.

Data Engineering System DesignAdvanced2 min readUpdated 11 Oct 2026

Delivery guarantees

GuaranteeMeaningRisk
At-most-onceEach message processed 0 or 1 timesData loss
At-least-onceProcessed 1 or more timesDuplicates
Exactly-onceEffect applied onceHard; only within boundaries

Networks fail after a write succeeds but before the acknowledgement arrives. The sender cannot tell whether to retry, so it retries. That makes at-least-once the realistic default.

What "exactly-once" products actually mean

  • Kafka transactions give exactly-once from Kafka topic to Kafka topic.
  • Spark Structured Streaming gives exactly-once into sinks that support it (checkpointed offsets plus idempotent or transactional sinks such as Delta).

Once data crosses into a system outside that boundary (an API, a database without transactions), the guarantee no longer holds.

Effectively-once = at-least-once + idempotent writes

TechniqueExample
Upsert on a natural keyMERGE ... ON order_id
Deterministic batch ids + ledgerReplaying batch 42 returns "already published"
Partition overwriteRewrite business_date=2026-01-05 completely
Dedup table of processed message idsSkip ids already seen

Watch the side effects

Emails, payments and API calls cannot be rolled back. Give each one an idempotency key, so a retry is recognised and ignored.

Finished this note?

Share