Big Data 4 min read

How Kafka Guarantees Exactly‑Once Delivery with Idempotent Producers

This article explains Kafka's idempotent producer feature, describing how enabling idempotence ensures that duplicate messages caused by retries or network issues are deduplicated so that each message is persisted only once in a partition, and outlines the underlying PID and sequence number mechanism.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
How Kafka Guarantees Exactly‑Once Delivery with Idempotent Producers

Idempotence means an operation can be performed multiple times but the result is the same as executing it once, ensuring the final system state remains unchanged.

In Kafka, idempotence is a producer‑side feature that prevents duplicate writes to a partition when the same message is sent multiple times due to network glitches, retries, or timeouts.

How Kafka Implements Idempotence

1. Enable the idempotent producer configuration: enable.idempotence=true 2. The producer automatically generates two identifiers:

Producer ID (PID) : a unique identifier assigned to each producer instance for its lifetime.

Sequence Number : a monotonically increasing number for each message sent by that PID.

The broker records the highest sequence number received from each PID. If a message arrives with a PID and a sequence number less than or equal to the recorded value, the broker treats it as a duplicate and discards it without writing to the partition.

Key Takeaways

Enabling idempotence guarantees that even if a producer retries sending a message, the message will appear only once in the target partition. The mechanism relies on the combination of PID and sequence number for precise deduplication. Kafka enables idempotence by default in newer versions (or when transactions are used), but it can also be turned on manually.

Idempotence applies to the “exactly‑once” semantics of the producer side; it does not cover consumer‑side processing or cross‑topic/partition consistency, which require transactional support.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Message QueueIdempotenceExactly-Once
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.