Raft is a consensus algorithm for maintaining an agreed sequence of operations across multiple servers in a distributed system. It organizes servers around an elected leader, which accepts proposed operations, replicates them in a log, and determines when they are committed. Servers apply committed operations in the same order to produce consistent state. Raft tolerates server crashes and communication failures as long as a majority of voting servers can communicate and make progress; it does not tolerate arbitrary malicious behavior by participating servers.
Purpose and development
Diego Ongaro and John Ousterhout introduced Raft in the 2014 paper In Search of an Understandable Consensus Algorithm. Its central design goal was understandability: the protocol separates leader election, log replication, and safety rules into components intended to be easier to explain and implement than Paxos.
Raft supports the replicated state machine approach to fault-tolerant services. Each server maintains a copy of a deterministic state machine, and all servers execute the same committed commands in the same order. A service can therefore continue operating after some servers become unavailable without losing operations that have already been committed, provided the protocol’s storage and failure assumptions hold.
Typical uses include coordination services, configuration stores, and strongly consistent databases. Raft establishes an ordered history within a consensus group; it does not by itself supply every feature of a database, such as query processing, indexing, or transactions across independent groups.
System model and quorum
Raft assumes that servers may stop, restart, or become temporarily unreachable. Messages may be delayed, lost, duplicated, or reordered. Servers follow the protocol rather than sending deliberately false information. This is a crash-fault model, not Byzantine fault tolerance.
For a fixed configuration with voting servers, a majority quorum contains
servers. A deployment of voting servers can therefore continue making progress with up to unavailable servers, assuming the remaining servers can communicate and storage remains usable. Three voters tolerate one unavailable voter; five tolerate two.
Any two majorities overlap. This intersection helps connect decisions made by different leaders, but it is not sufficient on its own: Raft also requires voting restrictions, log consistency checks, and commitment rules.
Persistent storage is essential. A server must preserve its current term, its vote for that term, and its log across restarts. Required state changes must become durable before the server sends replies that depend on them. Losing this information can invalidate the protocol’s assumptions.
Roles, terms, and leader election
Each server occupies one of three roles:
- Follower: responds to requests from leaders and candidates.
- Candidate: seeks election after an election timeout.
- Leader: coordinates log replication and communicates with followers.
Time is divided into numbered terms, which act as logical epochs. A term begins with an election attempt and may end without a leader if votes are split. At most one leader can be elected in a given term. Servers include their term in protocol messages; a server that discovers a higher term updates its term and becomes a follower.
Election procedure
Followers expect periodic communication from a leader, commonly called heartbeats. A follower that reaches its election timeout without receiving appropriate leader communication becomes a candidate. It increments its term, votes for itself, and sends RequestVote messages to other servers.
A voter grants its vote only if:
- The candidate’s term is acceptable.
- The voter has not already voted for another candidate in that term.
- The candidate’s log is at least as up to date as the voter’s log.
Log freshness is compared first by the term of the last entry, then by the last entry’s index if those terms are equal. A candidate with a higher last-log term is considered more up to date even if another candidate has more entries.
A candidate becomes leader after receiving votes from a majority. If no candidate wins, another election follows. Randomized election timeouts reduce the likelihood that servers repeatedly start elections together and split the vote.
Timeouts affect availability and performance rather than the fundamental safety rules. Extremely delayed messages can cause unnecessary elections, but they must not cause incompatible committed histories.
Leadership during a partition
A network partition can leave an old leader running while another component elects a leader in a higher term. Raft therefore does not guarantee that only one server believes itself to be leader at every instant.
Instead, it ensures that an isolated old leader cannot commit new operations without the required quorum. When it learns of the higher term, it steps down. This distinction is important when designing client routing and read behavior.
Log replication
The leader receives client commands and appends them to its log. Each log entry contains a command and the term in which the leader created it; its position supplies a log index.
The leader sends entries to followers using AppendEntries messages. These messages identify the index and term of the entry immediately preceding the proposed entries. A follower accepts the new entries only if its own log contains that preceding entry with the matching term.
If the consistency check fails, the leader retries from an earlier position. Once it finds a common prefix, it replaces the follower’s conflicting uncommitted suffix with the leader’s entries. A correct Raft execution does not overwrite committed entries.
This mechanism provides the log matching property:
If two logs contain an entry with the same index and term, then their entries through that index are identical.
The leader also communicates its commit index, allowing followers to learn which entries are safe to apply. Replication, commitment, and application are distinct events: an entry can be stored on a follower before it is committed, and a committed entry can await application.
The current-term commitment rule
An important subtlety is that a leader cannot directly conclude that an entry from an earlier term is committed merely because it currently appears on a majority of servers.
For a fixed configuration, a leader advances its commit index to by counting replicas only when:
- A majority of servers have stored entries through .
- The entry at was created in the leader’s current term.
Committing such an entry also commits all preceding entries. Thus, earlier-term entries become committed indirectly through the commitment of a later current-term entry.
This restriction is necessary because certain election sequences can otherwise leave an earlier-term entry replicated on a majority yet still subject to replacement. A newly elected leader can append a no-operation entry in its own term to establish commitment of the preceding log without waiting for a new client command.
Safety properties
Raft’s main safety properties describe what remains true despite failures and message delays:
| Property | Meaning |
|---|---|
| Election safety | At most one leader is elected in a given term. |
| Leader append-only | A leader does not overwrite or delete entries in its own log while acting as leader. |
| Log matching | Matching index-and-term entries imply identical preceding log prefixes. |
| Leader completeness | An entry committed in a term appears in the logs of leaders elected in later terms. |
| State machine safety | Once a server applies a command at a log index, no server applies a different command at that index. |
Election restrictions and commitment rules work together to establish leader completeness. Replicas may temporarily differ in how far they have progressed, but their applied histories cannot conflict.
Raft has been studied using formal verification. Such proofs apply to specific models and assumptions; they do not automatically establish the correctness of every implementation, storage layer, or operational extension.
Client semantics and reads
Retries and duplicate commands
A client may send a command, lose contact with the leader, and receive no response even though the command was committed. Retrying the command can cause it to execute again unless the service detects duplicates.
A replicated service can associate requests with a client identifier and sequence number and store the associated results in replicated application state. Raft alone does not make arbitrary external side effects execute exactly once.
Linearizable reads
Linearizability requires operations to behave as though they occurred atomically in a single order consistent with real-time ordering.
Reading a leader’s local state is not automatically linearizable. A partitioned former leader may still believe it is authoritative, and a new leader may not yet have applied all committed entries.
A conservative approach orders reads through the replicated log. More efficient approaches can avoid a new log entry for each read, but must establish the leader’s authority and wait until the relevant committed state has been applied. Common quorum-confirmed read paths require the leader to have committed an entry in its current term and to confirm its leadership through communication with a quorum.
Lease-based read optimizations require additional assumptions about time and clock behavior. Reads from arbitrary followers may return stale state unless the surrounding system supplies further coordination.
Membership changes and snapshots
Changing the voting configuration
Changing membership is more difficult than replacing a server list. An unsafe transition can allow nonoverlapping groups to make conflicting decisions.
Raft’s joint consensus approach introduces a transitional configuration containing both the old and new memberships. During this stage, elections and commitment require a majority of the old configuration and a majority of the new configuration. The system then commits the new configuration alone.
Some implementations use other carefully constrained reconfiguration procedures. Their safety depends on the exact transition rules; arbitrary membership changes are not safe merely because each configuration separately uses majority voting.
Snapshotting and recovery
A continuously growing log would eventually consume excessive storage and make recovery slow. Raft supports log compaction through snapshots.
A snapshot records application state through an applied log position, along with metadata such as the last included index and term and the relevant membership configuration. Log entries covered by a durable snapshot can then be discarded.
If a follower falls behind the retained log, the leader can transfer a snapshot instead of replaying every earlier command. Snapshot installation must preserve the relationship between application state, log positions, and subsequent entries.
Performance and operational limits
In normal operation, writes pass through one leader. Commitment ordinarily requires replication to a majority, so latency depends on network communication and durable storage. Waiting for the slowest server is unnecessary, but slow members of the fastest available quorum can still affect performance.
Common implementation techniques include batching commands, pipelining replication, and using many independent Raft groups. Such arrangements can distribute load across leaders, although operations spanning groups require additional coordination.
Principal limits include:
- Majority dependence: without a communicating majority, the group cannot commit new entries.
- Leader concentration: the leader coordinates replication and can become a processing or network bottleneck.
- Wide-area latency: geographically dispersed quorums increase communication costs.
- Election disruption: network instability, long process pauses, or storage stalls can trigger repeated leadership changes.
- Storage dependence: incorrect durability behavior or corrupted persistent state can violate the assumed failure model.
- No protection against malicious voters: ordinary Raft does not prevent participating servers from lying or otherwise departing from the protocol.
Raft’s response to partitions illustrates the CAP theorem: a service preserving linearizable behavior cannot guarantee successful operations in every disconnected component. Uncommitted entries can also be discarded after leadership changes, so application-level success responses must be tied to commitment rather than merely local log insertion.
Applications and related mechanisms
Raft is used in systems such as etcd and HashiCorp Consul to maintain replicated coordination state. Implementations differ in storage integration, membership procedures, read modes, and operational extensions.
It is related to, but distinct from, several other mechanisms:
- Paxos: also solves crash-tolerant consensus. Multi-Paxos commonly uses a stable leader to agree on a sequence of values, while Raft explicitly constrains how leaders are elected and how their logs evolve.
- Primary–backup replication: may resemble Raft’s leader–follower arrangement, but that arrangement alone does not establish safe failover or consensus.
- Two-phase commit: coordinates transaction outcomes across participants rather than serving as a substitute for Raft’s replicated-log agreement.
- Database transactions: provide application-facing atomicity and isolation guarantees that may use consensus internally but require additional mechanisms.
- Byzantine fault-tolerant consensus: addresses a stronger failure model and generally requires different quorum sizes and protocol rules.
Extensions such as pre-voting, leadership transfer, quorum checking, and nonvoting learners address practical operational needs. Their guarantees depend on how they are integrated with Raft’s core election, replication, and commitment rules.