Home/Labs/Raft Consensus Lab
All 280 Labs
INTERACTIVE LAB🗳️

Raft Consensus Algorithm Visualizer (Elections, Heartbeats & Split Brains)

Partition cluster nodes, trigger split elections, and watch Raft maintain quorum consensus. Simulate a 5-node distributed Raft cluster. Kill leader nodes, introduce network partitions, inspect election timeouts, and observe quorum validation (N/2 + 1).

Raft Distributed Consensus Simulator (5-Node Quorum)

Simulate leader elections, log entry replication, heartbeat sync, and split-brain partition tolerance.

Current Term: #1
Cluster healthy. Node 1 is Leader for Term 1 with 5/5 quorum.
Node 1Leader

Term: 1

Log Entries: 3

Heartbeat Sender
Node 2Follower

Term: 1

Log Entries: 3

Listening
Node 3Follower

Term: 1

Log Entries: 3

Listening
Node 4Follower

Term: 1

Log Entries: 3

Listening
Node 5Follower

Term: 1

Log Entries: 3

Listening

Committed Consensus Log Stream (Raft Log)

[1] SET x=10[2] SET y=20[3] SET z=30

How It Works Under the Hood

Raft is a distributed consensus algorithm designed to be understandable while providing complete fault tolerance equivalent to Multi-Paxos. A Raft cluster decomposes consensus into three independent sub-problems: Leader Election, Log Replication, and Safety. Nodes exist in one of three states: Follower, Candidate, or Leader. Leaders send periodic heartbeat RPCs to maintain authority. If a Follower receives no heartbeats within a randomized election timeout [150ms, 300ms], it transitions to Candidate and solicits votes. A candidate wins when it secures votes from a majority (quorum) of cluster nodes (e.g., 3 out of 5 nodes).

Core Architectural Principles

  • Majority Quorum: A cluster of 2F + 1 nodes can tolerate F node failures without losing availability.
  • Randomized Election Timeouts: Prevents split-vote ties when multiple followers suspect leader failure simultaneously.
  • Log Matching Property: If two logs contain an entry with the same index and term, they are identical up to that point.
Interview Round Script

When an interviewer asks how to avoid split-brain states during network partitions, explain that only the partition containing a strict majority (N/2 + 1) of nodes can elect a leader or commit log entries. The isolated minority partition simply queues requests without committing.

Key Trade-Offs

Synchronous quorum round-trips on write operations vs absolute consistency and partition tolerance (CP in CAP theorem).

Related Curriculum Chapter

Raft Distributed Consensus: Leader Election & Log Replication

Read Full Chapter Blueprint

Explore More Interactive Labs

View All 280 Labs