An Overview of the Raft Distributed Consensus Algorithm
Raft is a fault‑tolerant distributed consensus protocol that simplifies Paxos by electing a single leader each term to coordinate client requests, replicate logs to a majority of servers, ensure safety through up‑to‑date voting, handle failures with randomized timeouts, resolve log conflicts, and compress logs via snapshots.
Raft is a distributed consensus algorithm designed to manage log replication in a fault‑tolerant way. It was created to simplify the Paxos algorithm, making the protocol easier to understand and implement.
Raft solves the CP part of the CAP theorem (Consistency and Partition tolerance) but does not address Availability. The algorithm works by electing a single leader among a set of servers (candidates) that then coordinates all client requests and log replication.
Server roles : • Leader – handles all client requests and issues AppendEntries RPCs to replicate log entries. • Follower – responds to RPCs from the leader or candidates. • Candidate – a follower that starts an election when it does not receive heartbeats.
Time in Raft is divided into terms . Each term begins with an election; at most one leader can exist per term. Servers store a monotonically increasing term number and exchange it in every RPC.
Log replication : the leader appends client commands to its log, then sends AppendEntries RPCs to followers. When a log entry is stored on a majority of servers it is considered committed and the leader applies it to the state machine, returning the result to the client.
Raft guarantees safety by ensuring that a candidate can become leader only if its log is at least as up‑to‑date as any other server’s log. The RequestVote RPC carries the candidate’s last log index and term; followers reject votes from candidates with older logs.
To handle failures, Raft uses a random election timeout (e.g., 150‑300 ms). If a follower does not receive a heartbeat before the timeout expires, it becomes a candidate and starts a new election. Randomized timeouts reduce the chance of split votes.
When logs diverge, the leader finds the last matching entry on each follower and overwrites any conflicting entries, ensuring that all followers eventually have the same log as the leader.
Raft also supports log compression via snapshots. Once a snapshot of the state machine is taken, all log entries preceding the snapshot can be discarded, preventing unbounded log growth.
The document concludes with references to the original Raft paper, translations, videos, and implementations such as Ant Financial’s sofa‑jraft library.
vivo Internet Technology
Sharing practical vivo Internet technology insights and salon events, plus the latest industry news and hot conferences.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.