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
- Leader appends entry #7 to its own log. It is now written, not committed.
- Leader sends #7 to its followers.
- Followers append #7 to their logs and reply "got it".
- Leader sees a majority holds #7 and moves its commit pointer to 7. #7 is now committed.
- Leader replies "done" to the client.
- Followers learn "commit = 7" on the leader's next message.
So every server's log has two parts:
| Part of the log | What 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 next | Fate of entry #7 |
|---|---|
| Followers come back and reply | Commits late. Same entry, same position. |
| Leader is replaced, and the new leader has #7 | Survives. The new leader will commit it. |
| Leader is replaced, and the new leader doesn't have #7 | Deleted (truncated) from every log that has it. |
| Leader is stuck in a minority partition | Stays 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.
| Raft | Kafka | |
|---|---|---|
| Persisted to disk | currentTerm, 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 restart | Commit 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. |
| Note | Some 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.
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.
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.
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.
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 arrives | L appends it to its own log | S3 appends it to its own log |
| Copies it can get | L + S2 = 2 | S3 + S4 + S5 = 3 |
| Majority (3)? | No, never committed | Yes, committed |
| What the client sees | No 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
- L receives any message stamped term 2. A higher term means a newer leader exists, so L immediately steps down to follower.
- S3 replicates its log to L. The two logs match up to entry 3 and differ after that.
- L deletes A and B and copies P, Q, R. In Raft, the leader's log always wins.
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:
- Client 1 times out waiting for L. In Kafka,
request.timeout.mssets this limit. - It refreshes its cached note and learns "leader = S3".
- 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 concept | Kafka equivalent |
|---|---|
| Term | Leader epoch, bumped by the controller on every leader change |
| Majority needed to commit | Every member of the ISR must hold the write (with acks=all) |
| Majority elects the leader | The controller (itself on Raft, KRaft) picks the new leader from the ISR |
| Old leader deletes uncommitted entries | Old 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.