Term — the logical clock
Raft replaces the wall clock with a simple round counter called the term, and one universal rule — when any server sees a bigger round number than its own, it adopts that number and becomes a plain follower — is what keeps the whole cluster's sense of time honest.
You know from scene 01 that safety has to hold even when messages arrive late, out of order, or not at all — and that the wall clock can't be trusted. So before Raft can do anything else, it needs its own notion of time: a counter the whole cluster can agree on without asking a clock. That counter is what this scene builds.
Scene 02
Term — Raft's round counter
- Watch
- Try it
- Predict
- Capture
You know from scene 01 that the cluster has to agree on a history without trusting the wall clock. The question this scene answers is: what does Raft use instead? Look at the three servers. They all say they are on round 1. One server (S1) is currently in charge — it is allowed to make decisions for round 1 and tell the others what to do. The other two are just listening. Three new words for what you see. First, the round counter itself: think of it like the season number of a TV show — once you start season 4, season 3 is over forever. The precise term is term — a monotonically increasing integer, shared by the whole protocol, where at most one server is ever in charge during a single term. Second, each server keeps its own copy of 'what season do I think we are in?' — the precise name for that field is currentTerm. Third, the role each server is playing right now: passive listener is called a follower, the one in charge is called the leader, and (you'll meet this one next phase) a server running for the job is called a candidate.
Highlighted lines are the ones running in the diagram right now.
def onReceiveRPC(rpc):if rpc.term > currentTerm:currentTerm = rpc.term # adopt newer termvotedFor = None # clear vote for new termrole = follower # step downpersist(currentTerm, votedFor) # §5.2 persist barrierif rpc.term < currentTerm:reply(term=currentTerm, success=False)return# rpc.term == currentTerm: dispatch to kind-specific logic
# Persisted (fsync'd before responding to dependent RPCs):currentTerm : monotonic int # latest term observedvotedFor : ServerId | None # vote granted in currentTermlog : list[{term, cmd}] # replicated entries, term-tagged# Volatile on every server:commitIndex : int = 0lastApplied : int = 0# Volatile on leader only:nextIndex : dict[ServerId, int]matchIndex : dict[ServerId, int]
Where this sits in Build Raft — consensus you can defend
Scene 02 of 12. A term is a monotonic int that segments time, with at most one leader per term. The universal step-down rule (any server seeing T' > currentTerm becomes a follower at T') is the simplest mechanism in Raft and underpins everything else.
Up next. Now that every message and every server carries a round number, the question 'who is the leader right now?' simplifies to 'who got enough votes in round T?' — a counting problem, which the next scene answers using one fact about majorities.
All 12 scenes in Build Raft — consensus you can defend · Every curriculum