Consensus & Leader Election (Raft)

How clusters agree on one Leader and replicate state safely despite crashes and split-brains

Difficulty: Advanced · Read time: 10 min · Access: Step-1 Preview + Knoera Pro

How It Works

Distributed coordination engines—such as `etcd` (Kubernetes key-value store), HashiCorp Consul, Apache ZooKeeper, and CockroachDB—rely on fault-tolerant consensus algorithms like Raft or Paxos so a cluster agrees on a single Leader and an identical ordered state log even when servers crash or networks partition. Raft decomposes consensus into two clear mechanisms: Leader Election (using randomized election timeouts and strict majority votes) and Log Replication (committing entries only after a majority quorum persists them to disk).

Why It Matters

Without formal consensus, a network partition can trick two isolated servers into both believing they are the active Primary ("split-brain")—causing both to accept conflicting writes, grant the same distributed lock to two clients simultaneously, and permanently corrupt cluster metadata.

Interactive Architecture Scenarios

  • Raft Leader Crash & Majority Re-Election
  • Failure Mode: Network Partition & Stale Minority Leader

Related Lessons in Distributed Systems & Resiliency