Commit and Split Brain: Two Leaders, One Official Log

Part A — What "Commit" Means

Commit is not a separate write and not a separate step on disk. It is a pointer the leader moves forward once enough servers hold an entry.

A1. The write path

  1. Leader appends entry #7 to its own log. It is now written, not committed.
  2. Leader sends #7 to its followers.
  3. Followers append #7 to their logs and reply "got it".
  4. Leader sees a majority holds #7 and moves its commit pointer to 7. #7 is now committed.
  5. Leader replies "done" to the client.
  6. Followers learn "commit = 7" on the leader's next message.

So every server's log has two parts:

The leader log holds entries one to nine. The commit pointer sits at seven. Entries one to seven are committed: on a majority and guaranteed forever. Entries eight and nine are written but not committed, and could still be deleted by a future leader.
Side read · One log, two parts — and the pointer is the only thing separating them
Part of the logWhat it means
Committed (at or below the pointer)On a majority, so it survives any future leader change. Safe to show readers and to acknowledge to clients.
Uncommitted (above the pointer)Physically in the log, but not promised to anyone yet.

Raft calls the pointer the commit index. Kafka calls it the high watermark (HW), and consumers can only read up to it, so they never see uncommitted data.

A2. When the replies don't come

The entry stays in the leader's log, above the commit pointer. Nothing is deleted right away, and the leader keeps re-sending it. What happens next decides its fate:

What happens nextFate of entry #7
Followers come back and replyCommits late. Same entry, same position.
Leader is replaced, and the new leader has #7Survives. The new leader will commit it.
Leader is replaced, and the new leader doesn't have #7Deleted (truncated) from every log that has it.
Leader is stuck in a minority partitionStays uncommitted until the network heals, then deleted. This is Part B.

"Uncommitted" means "not guaranteed yet", not "failed". It might still commit, or it might be deleted.

A3. Is the commit pointer itself durable?

No, and it doesn't need to be. What makes an entry durable is that it sits on a majority of servers. The pointer is only the leader's cached conclusion about that fact, and it can be worked out again after a crash.

RaftKafka
Persisted to diskcurrentTerm, votedFor and the log. The commit index is listed as volatile state in the Raft paper.The log, plus the HW checkpointed only periodically to replication-offset-checkpoint (every 5s by default, replica.high.watermark.checkpoint.interval.ms).
After a restartCommit starts at 0. A new leader commits one entry from its own term, which commits everything before it. Followers relearn the pointer from the leader's next message.The HW may be stale (too low). The broker catches up from the leader's fetch responses.
NoteSome implementations persist it as an optimisation (etcd keeps Commit in its HardState), but correctness doesn't depend on it.Old Kafka truncated to the stale HW on restart and lost acked data. KIP-101 fixed this by truncating based on leader epochs instead. Step by step →

Part B — Split Brain, Step by Step

B1. Setup

5 servers, L is the leader. A write is committed once 3 of 5 servers hold it.

Five servers, L, S2, S3, S4 and S5. L is the leader in term 1. A write is committed once three of the five hold it.
Side read · B1 — five servers, one leader, and a write commits at 3 of 5

B2. The network splits

A network failure divides the servers into two groups that can't reach each other. L hasn't crashed: it's still running and still believes it is the leader.

A network failure divides the servers into two groups that cannot reach each other. Side A holds L and S2; L has not crashed and still believes it is the leader. Side B holds S3, S4 and S5.
Side read · B2 — the network splits, and nobody has crashed

B3. The bigger side elects a new leader

S3, S4 and S5 stop hearing from L. After a timeout, S3 starts an election for term 2 and wins 3 votes, a majority. Now two servers both think they are leader. That is split brain.

Split brain. Side A: L, still leader of term 1, and S2: two servers, which can never win an election. Side B: S3 has started an election for term 2 and won three votes, a majority, so S3 is leader of term 2, with S4 and S5. Two servers now both think they are the leader.
Side read · B3 — split brain: two leaders, but only one of them was elected by a majority

Side A can never do the same. With only 2 servers it can never win an election. Only one side of any split can hold a majority.

B4. Where client writes go

A client's write goes to one server, never to both leaders, and the choice isn't random. Every client caches a note saying "the leader is X" (in Kafka, the producer's metadata) and sends each write there. Two things decide which leader a client ends up using:

  • Which side it can reach. A client that can only reach Side A can only talk to L.
  • How fresh its cached note is. A client whose note still says "leader = L" keeps sending there, even if it could reach S3.
Client 1 has a cached note saying the leader is L, and sends write A to L on side A. Client 2 has a cached note saying the leader is S3, and sends write P to S3 on side B. Each leader sees a different stream of writes and neither sees the other’s.
Side read · B4 — each client writes to the leader its cached note names, never to both

Each leader sees a different stream of writes, from different clients. Neither ever sees the other's.

B5. Both leaders accept writes, only one can commit

Old leader L (Side A)New leader S3 (Side B)
Write arrivesL appends it to its own logS3 appends it to its own log
Copies it can getL + S2 = 2S3 + S4 + S5 = 3
Majority (3)?No, never committedYes, committed
What the client seesNo answer. The request waits, then times out."Success"
  • Accept means the write is added to that leader's own log. Both leaders do this.
  • Commit means the write is on a majority and the client is told "done". Only S3 can do this.

B6. The network heals

When the network heals the two logs are compared. L holds 1, 2, 3, A, B: A and B were appended in term 1 and never committed. S3 holds 1, 2, 3, P, Q, R: P, Q and R were committed in term 2. The logs match up to entry 3 and differ after that.
Side read · B6 — the logs agree up to entry 3 and fork after it
  1. L receives any message stamped term 2. A higher term means a newer leader exists, so L immediately steps down to follower.
  2. S3 replicates its log to L. The two logs match up to entry 3 and differ after that.
  3. L deletes A and B and copies P, Q, R. In Raft, the leader's log always wins.
After reconciliation L holds 1, 2, 3, P, Q, R, identical to every other server. Entries A and B were deleted.
Side read · B6 — L drops A and B and copies P, Q, R from the term-2 leader

B7. Why deleting A and B is safe

A and B never reached a majority, so no client was ever told they succeeded. Deleting them breaks no promise. The data isn't lost either, because the clients that sent them are expected to retry:

  1. Client 1 times out waiting for L. In Kafka, request.timeout.ms sets this limit.
  2. It refreshes its cached note and learns "leader = S3".
  3. It retries write A against S3. The retry succeeds, and A lands in the official log.

Here the retry is safe because L could never reach a majority, so the original A was certain to be deleted. In general a timeout is ambiguous (see the A2 callout), which is why Kafka producers retry with idempotence on.

B8. Kafka's version

Raft conceptKafka equivalent
TermLeader epoch, bumped by the controller on every leader change
Majority needed to commitEvery member of the ISR must hold the write (with acks=all)
Majority elects the leaderThe controller (itself on Raft, KRaft) picks the new leader from the ISR
Old leader deletes uncommitted entriesOld leader truncates its log to match the new leader (see Commit Semantics)

A partition leader cut off from the controller can't shrink its ISR, because ISR changes must go through the controller. With acks=all it keeps waiting for followers it can't reach, so its writes never commit, the same outcome as L above.

Two leaders can exist for a while, but only the side with a majority can commit, so only one version of the log ever becomes official. Everything the other side accepted was never promised to anyone and is safe to throw away.