K-Raft Builder

Interactive LEGO Consensus Playground

Term 1
Leader Electing…
Committed 0
0/4
Starting LEGO cluster…
1.0x
🧢 Follower 📣 Candidate 👑 Leader 💥 Crashed
💡 Click any LEGO character to crash/revive · Drag across board to build a partition wall (click wall to remove)

📘 How the Raft Consensus Algorithm Works

Raft keeps a cluster of independent servers agreeing on the exact same sequence of commands—even when machines crash or network links break.

👑 1. Leader Election & Terms

Time in Raft is divided into numbered Terms. Every LEGO character starts as a Follower with a randomized countdown ring. If a Follower’s timer expires without receiving a heartbeat from a Leader, it increments the term, becomes a Candidate, votes for itself, and sends RequestVote messages. The first Candidate to win a majority (3 out of 5) earns the Golden Crown. Randomized timeouts ensure split votes resolve quickly.

🧱 2. Log Replication & Commits

All client commands go to the Leader, which appends each new LEGO brick to its own log as uncommitted (dashed) and broadcasts AppendEntries packets to Followers. Once a majority of servers safely store that brick, the Leader marks it Committed (solid) and notifies Followers in subsequent heartbeats so every server snaps the exact same tower in order.

🚧 3. Crashes & Network Partitions

Because decisions require a majority quorum, a 5-node cluster keeps running smoothly even if 2 servers crash or are cut off behind a partition wall. A stranded minority side can never elect a leader or commit new bricks—preventing split-brain conflicts. When the wall is healed or crashed characters revive, they automatically sync up with the majority Leader’s log.