Skip to main content
InterviewHubPRO
Section Overview
Q21

Question 21 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

42%
Apache Kafka Streaming (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

What are Idempotent Producers (`enable.idempotence=true`) and how do they eliminate duplicates?

senior LevelSystem Design

In Simple Words: When a producer sends a batch of records, the broker may successfully write them to disk, but the network ACK packet drops before reaching the producer. The producer assumes a failure and retries, creating duplicate records in the partition log.

Idempotence Mechanics (Enabled by default in modern Kafka):

  1. The broker assigns each producer a unique 64-bit Producer ID (PID) via InitProducerId.
  2. Each batch of records produced by that client includes a monotonically increasing Sequence Number per partition.
  3. When the broker receives a batch:
    • If incoming_seq == expected_seq: Commits data and increments expected sequence.
    • If incoming_seq <= expected_seq - 1: Broker detects a duplicate retry! It acknowledges the write to the producer but drops the duplicate records from disk.