Course contentsShow
← Computer Science
Lesson 2668 of 2,87259. Consensus and ReplicationFree lesson

Commitment Rules and Safety

Learn when log entries are considered committed, how leaders determine commitment, and why old entries need special handling.

Commitment Rules and Safety

What you'll learn: How Raft guarantees that committed log entries are permanent and never lost, no matter what failures occur.

When Is a Log Entry Committed?

In Raft, a log entry is committed when the leader has successfully replicated it to a majority of servers (including itself). Once committed, an entry can be applied to the state machine and will never be lost.

The leader tracks which entries are committed by monitoring acknowledgments from followers. When a majority confirms they've stored an entry at a given index, the leader marks it as committed and informs followers in subsequent AppendEntries RPCs.

The Critical Safety Rule

Here's where it gets subtle: a newly elected leader cannot immediately commit entries from previous terms by simply counting replicas. Why? Because those old entries might have been replicated to a majority but never actually committed before the old leader crashed.

Instead, Raft uses this rule: a leader can only commit entries from its current term by counting replicas. Old entries are committed indirectly when a new-term entry is committed—which proves the leader's log is durable across a majority.

Why Old Entries Need Special Handling

Imagine a leader replicates entry X from term 3 to three servers, but crashes before committing it. A new leader in term 4 might overwrite X on some servers. If we naively counted replicas of X to commit it in term 5, we'd risk committing an entry that was already overwritten—violating safety!

By requiring a current-term entry to reach majority first, Raft ensures the leader's entire log (including old entries) is durably preserved.

Key Takeaway: Raft commits entries when replicated to a majority, but leaders can only commit current-term entries by counting; old entries commit indirectly, guaranteeing safety even during leadership changes.