How it works · Go library for agreement between servers
How etcd’s Raft works
Several servers keep the same list of changes in the same order, even when some of them crash. This is the library Kubernetes’ database is built on.
Think of it like this. A committee with one chair. Only the chair proposes, a change counts once most members have written it down, and if the chair goes quiet the members elect another.
The library is only the rules. Your program sends the messages and writes the disk, and tells the library what happened.
- 🧠 The state machine The rules: what a follower, a candidate and a leader each do with every message. raft.go
- 📜 The log The ordered list of changes, and how far along it everyone has agreed. log.go
- 🔌 The node What your program talks to: propose a change, tick the clock, collect what to do next. node.go
- 📊 Progress The leader’s note of how far each follower has got. tracker/progress.go
- 💾 Storage The few things the library asks of your disk. storage.go
Follow one thing through: the leader stops answering
- Each follower counts clock ticks since it last heard from the leader.raft.go
- Each waits a slightly different, random time, so they rarely all stand at once.raft.go
- The first to run out becomes a candidate, moves to a new term, votes for itself and asks the others.raft.go
- A server votes yes only if the candidate’s log is at least as up to date as its own.log.go
- With votes from more than half, it becomes leader.raft.go
- It starts sending heartbeats, and the others go back to following.raft.go
The clever bit: No network, no disk, no clock
The core never sends a message, writes a file or reads the time. Your program calls Tick() when time passes and Step() when a message arrives, and gets back a Ready: entries to save, messages to send, changes that are now safe to apply. Because the rules are a plain function of what went in, a test can replay any order of crashes and lost messages exactly, which is how a system this subtle gets trusted.
Words you’ll meet
- term
- A numbered period with at most one leader. A higher term always wins.
- log
- The ordered list of changes every server keeps.
- quorum
- More than half the servers. Any two quorums share at least one server.
- committed
- Stored on a quorum, so it can never be lost.
Good questions to ask next
- Why must a candidate’s log be up to date to win?
- What happens when two servers both think they are leader?
- How does a follower that fell behind catch up?
Open etcd’s Raft in Bento and ask them there. It reads the project in your browser, draws its parts as a map you can press, and opens the real code behind each one.
Take etcd’s Raft apart yourself.
Free and open source. Nothing to install, no account.
Ideas inside it
More projects, taken apart
Written by hand from the code as it was on 2026-11-19 (commit ae830f4). etcd’s Raft belongs to its authors; this page is an independent explanation. Spot a mistake? Tell us.