techdiagrams.net
← All posts

Raft, explained with one diagram: how clusters agree on anything

Suchait Gaurav· · 3 min read distributed-systemsconsensusraft

Every system that promises "strongly consistent and highly available-ish" — etcd under Kubernetes, Consul, CockroachDB, TiDB — has a consensus algorithm at the bottom, and these days it's almost always Raft. Raft's claim to fame is being understandable, so let's take it at its word: one diagram, one write, start to finish.

A 5-node Raft cluster replicating a write from the leader to four followers

This diagram is a real techdiagrams document — download the JSON and import it into the editor via File → Import.

One leader, one term, one log

Raft's first simplification: all writes go through a single leader. No multi-master conflict resolution, no vector clocks — at any moment the cluster has exactly one node allowed to accept writes, elected for a numbered term (our diagram is in term 7).

When the client sends write x=5:

  1. The leader appends the entry to its own log — uncommitted.
  2. It ships the entry to every follower in an AppendEntries RPC (the same message type doubles as the heartbeat when empty).
  3. Each follower appends and acks.
  4. The moment a majority — 3 of our 5 nodes, leader included — has the entry, it's committed: the leader applies it and answers the client.

Note what that majority rule buys in the diagram: Node E is slow, still catching up over its dashed link. Nobody waits for it. Two dead or lagging nodes are simply survivable; the write path only ever moves at the speed of the third-fastest node. That's the availability half of the deal.

Elections: what happens when the leader dies

The consistency half comes from how leadership changes hands. Followers expect heartbeats. If a follower hears nothing for a randomized election timeout (typically 150–300ms), it assumes the leader is gone, increments the term, votes for itself, and asks the others for votes.

Two rules make this safe:

The randomized timeout is the quietly brilliant bit: it makes split votes rare (someone times out first), and when they do happen, everyone re-rolls the dice next term. No coordination needed to avoid coordination failure.

What Raft costs you

Consensus is not free, and honest architecture means knowing the bill:

Try killing the leader yourself

This is exactly the kind of design that reads fine on paper and surprises you in the failure cases — which is why it makes a great simulation. Import the diagram into techdiagrams.net, and you have a living starting point: attach contracts, declare "no acknowledged write is ever lost," and experiment with what a leader crash between append and commit does to your assumptions. Consensus is much stickier once you've watched it break.

Get the next post in your inbox

Engineering notes from building an architecture editor that runs — React traps, simulation internals, AI product patterns. No spam, unsubscribe anytime.