ARCHIVED from builddistributedsystem.com on 2026-04-28 — URL: https://builddistributedsystem.com/tracks/consensus/tasks/task-6-3-commitment
TASK

Implementation

Implement log entry commitment:

  1. Leader tracks matchIndex for each follower
  2. For each index N, count how many nodes have matchIndex >= N
  3. If majority have entry N, and entry N is from current term, commit N
  4. Advance commitIndex to highest committed N
  5. Notify followers of new commitIndex in next heartbeat

Important: Only commit entries from current term to satisfy the Raft safety property.

Sample Test Cases

Commit on majority replicationTimeout: 5000ms
Input
{
  "src": "c0",
  "dest": "n1",
  "body": {
    "type": "init",
    "msg_id": 1,
    "node_id": "n1",
    "node_ids": [
      "n1"
    ]
  }
}
Expected Output
{"src":"n1","dest":"c0","body":{"type":"init_ok","in_reply_to":1,"msg_id":0}}

Hints

Hint 1
Entry committed when on majority
Hint 2
Use matchIndex to count replicas
Hint 3
Only commit entries from current term directly
OVERVIEW

Theoretical Hub

Commitment

An entry is committed when the leader knows a majority have it. Committed entries are durable - they will survive leader changes. The leader advances commitIndex when majority confirms.

Current Term Requirement

Leaders only directly commit entries from their own term. Entries from previous terms are committed indirectly when a current-term entry is committed after them. This prevents a subtle safety violation.

Key Concepts

commitmentmajorityquorum
main.py
python
Implement Entry Commitment - The Consensus | Build Distributed Systems