Raft Consensus Lab - Internet Explorer
Address
https://freetolearn.world/raft-consensus-lab.html
free to learn.world
← Course Directory

Distributed Systems · Zero Background Needed · Visual Primer + 9 Interactive Labs · Free

Raft Consensus: How Cloud Databases Agree Without Split-Brain

If your app stores data on one computer, a single power failure takes everything offline. If you copy data across two computers and a cut network cable splits them into two disconnected islands, both sides might accept conflicting writes—a disaster called split-brain. Distributed consensus is the rulebook that lets a group of computers act like one unbreakable machine, and Raft is the algorithm inside Kubernetes's cluster database (etcd), CockroachDB, Consul, and production cloud databases that elects one leader, requires a quorum (minimum agreeing majority, such as 3 of 5) before confirming writes, and keeps every copy identical even as machines crash or cables break.

Start from zero (interactive course) 3D Watch & Poke walkthrough 5-rung Watch & Poke studio 5-Rung Agent Track

Zero background needed
Opens with a visual Start Here primer explaining why 1 or 2 servers fail, how majority quorums (3 of 5 agreeing servers) prevent split-brain, and what every term on screen means.
Real teaching before every trace
Every chapter explains the concept in plain English and walks through a concrete step-by-step example before you predict, step packets, and inject faults.
Zero setup
Runs completely offline in your browser with interactive 2D/3D cluster views, or run all 32 Node tests locally with zero dependencies.

Three Ways In · Layer 3 of 3 · Node.js 22+ · Zero Dependencies

Build With Your Coding Agent — 5 Rungs + Planted Traps

Build a single-node Raft consensus state machine tested inside a deterministic packet fault-injector with your coding agent across five rungs: split-vote elections & log freshness, conflict-safe AppendEntries backtracking, the Figure 8 current-term commit rule, read-index quorum leases, and crash-safe persistence + log compaction. Each rung gives you an architect prompt for Claude Code, Codex, or Cursor, a planted bug that unguided agents write, and a deterministic test suite that catches it.

  1. Terms & elections: Term step-down, single vote per term, and (lastLogTerm, lastLogIndex) freshness check — Planted trap: Comparing log length before last log term, or forgetting to clear votedFor on a higher term.
  2. Log replication: Idempotent AppendEntries matching and fast conflict backtracking — Planted trap: Blindly truncating the suffix on a delayed duplicate AppendEntries and deleting newer entries.
  3. Figure 8 commit rule: Advancing commitIndex only via entries from the leader's current term — Planted trap: Committing an old-term entry as soon as it sits on a majority, allowing a later leader to overwrite it.
  4. Linearizable reads: Heartbeat quorum round (ReadIndex) before serving leader reads — Planted trap: Serving reads locally whenever role === 'leader', returning stale data during a network partition.
  5. Crash-safe state & snapshots: Synchronous persistence before outbound messages plus InstallSnapshot compaction — Planted trap: Sending RequestVote or AppendEntries replies before flushing (currentTerm, votedFor, log).
unzip agent-track.zip && cd raft-consensus-lab/agent-track
node --test test/*.test.mjs
mkdir -p src/mine
RAFT_IMPL=src/mine/raft.mjs node --test test/rung-01.test.mjs

Download 5-Rung Agent Track (agent-track.zip) Read AGENT-TRACK.md on GitHub Open agent-track/README.md on GitHub

Inside the course

  • Start Here — What & Why: Why naive replication double-books data, how majority quorums and numbered election rounds stop split-brain, and a plain-English map of the lab screen.
  • 1–3 Elections & split brain: uncommitted client writes, randomized election timers that break 2–2 ties, and why stale minority leaders cannot confirm writes.
  • 4–6 Replication & faults: log backtracking after crashes, why old-round entries need a current-round anchor (the Figure 8 safety rule), and live packet drops/delays.
  • 7–9 Production transitions: compacting old logs into snapshots, swapping voting servers safely in two steps, and a split-brain recovery exam.

Local test & source checkout

git clone https://github.com/itsHabib/free-to-learn.git
cd free-to-learn
git switch --detach 7dba0d743224c10a707307769782b0db3f9a2a1a
cd courses/raft-consensus-lab
node --test

Browse the pinned source on GitHub · Reuse terms

cluster-trace.txt - Notepad

A, B split from C, D, E.
Leader B logs slot 2 (X=9) locally.
Network split cuts before a majority acknowledgment.

C wins term 2 and writes X=4.

Step packets, trigger election.
Prove what committed vs overwritten.

Give feedback on this course →

Course overviewInternet
Mission.txt - Notepad

Learning without paywalls.

Find what people pay to learn.
Build a great course. Give it away.

One course at a time.

Usage & privacy

Start