Commit Semantics

Five topics entangled in ways that matter in production: commit semantics, consumer rebalancing, exactly-once semantics, partition throughput/latency, and zero-copy I/O.

The Full Path for a Single Produce (acks=all)

  1. Leader appends record to its local log segment (LEO advances)
  2. Leader waits for every ISR follower to fetch that record and acknowledge (each advances its own LEO)
  3. Once ALL ISR followers have fetched up to that offset, leader advances HW
  4. Leader sends ack back to producer
  5. Consumers can now read that offset

The Three-Config Interaction

ConfigRole
replication.factor=3How many copies exist total
acks=allProducer waits for all ISR members
min.insync.replicas=2Minimum ISR size before writes are rejected

With rf=3, min.isr=2, acks=all: a write succeeds if at least 2 brokers (leader + 1 follower) are in ISR and both acknowledge.

What Happens When the Leader Crashes After Acking, Before Followers Replicate?

CaseWhat happens
A — Follower already replicated (HW advanced)Message is committed. The new leader (elected from ISR) has it. No loss.
B — Follower had not replicated (HW not advanced)With acks=all, this cannot happen — the leader would not have sent the ack until followers acknowledged. The producer's ack means HW already advanced.
C — acks=1 (leader only)Leader acks after writing locally, crashes before followers fetch. New leader elected from ISR — followers are behind. The message is lost. The producer thinks it succeeded.

Truncation on Leader Election

When a new leader is elected, the new leader's log becomes the official one. The leader never truncates its own log. Each follower, and the old leader when it comes back, asks the new leader where its log stops matching. It deletes everything from that point and copies the rest from the new leader. Kafka finds that point using leader epochs, a record of which leader wrote each part of the log.

In the example below, the two logs stop matching at offset 3, which is also the old HW. So "truncate to the HW" and "truncate to where the logs stop matching" give the same answer here. They don't always give the same answer.

Three rows of the same partition log. Row one, the old leader at the moment it crashed: offsets 0, 1 and 2 at or below the high watermark HW=2, committed; offsets 3 and 4 above the HW, never committed. Row two, the newly elected leader: offsets 0, 1, 2, HW=2. Row three, the old leader when it rejoins: it truncates its log to offset 2, discarding its own uncommitted 3 and 4, then replicates offsets 3 and 4 from the new leader.
A returning leader discards only what sat above the high watermark

The guarantee: a message acked with acks=all (at rf=3, min.isr=2) survives any single broker failure, and a complete cluster restart. It will not survive if more than rf − min.isr brokers fail simultaneously.