The Raft Consensus Algorithm
The Raft consensus algorithm[1] is a protocol designed to manage a replicated log[2] in a distributed computing system. It provides a strict mechanism for multiple independent nodes to agree on a sequence of state transitions, ensuring that all participating nodes in a cluster eventually reach the exact same state, even if some nodes fail or network partitions occur. By electing a single leader and forcing all state changes to flow exclusively through that leader, Raft simplifies the complex problem of distributed consensus into distinct, mathematically manageable subproblems. These subproblems include leader election, log replication, and safety.[23]
Developed by Diego Ongaro and John Ousterhout at Stanford University[3] in 2013 and formally published in 2014, Raft was created as a direct response to the pedagogical and practical difficulties associated with the Paxos algorithm[4]. Paxos, introduced by Leslie Lamport in 1989, had long been the standard for distributed consensus, but its highly theoretical structure made it notoriously difficult to understand and implement correctly in real software systems. Raft achieves the exact same fault tolerance and performance characteristics as Paxos but uses a completely different architectural structure that prioritizes understandability and practical software engineering. It minimizes the state space and restricts the ways in which nodes can interact, significantly reducing the number of edge cases developers must consider when building fault-tolerant systems.
Today, Raft serves as the foundational consensus protocol for many modern distributed databases, message brokers, and container orchestration systems. It powers the underlying coordination mechanisms of Kubernetes via etcd[5], manages service discovery and configuration in HashiCorp Consul[6], and ensures strict data consistency in distributed SQL databases like CockroachDB[7]. Its design has heavily influenced how the software industry approaches fault tolerance, shifting the focus from theoretical abstraction to practical, understandable implementation.
Definition and Problem Statement
In distributed systems, consensus is the fundamental problem of getting a group of independent, networked processes to agree on a single data value or a sequence of values. This agreement is necessary to maintain a consistent state across multiple physical machines, a concept formally known as state machine replication[8]. In a replicated state machine architecture, a set of servers computes identical copies of the same state. The principle dictates that if two identical deterministic state machines begin in the exact same initial state and process the exact same sequence of inputs, they will arrive at the exact same final state and generate the exact same outputs. This allows the overall system to continue operating seamlessly even if a subset of the servers crashes or becomes unreachable.
The primary challenge in distributed consensus is maintaining this agreement in the presence of unreliable networks and hardware failures. Networks can delay, duplicate, reorder, or completely drop messages. Servers can halt, restart, or lose connectivity without warning. The theoretical difficulty of this problem is defined by the FLP impossibility result[9], published by Fischer, Lynch, and Paterson in 1985. The FLP theorem proves that in a purely asynchronous distributed system where even a single process might crash, no deterministic consensus algorithm can guarantee that it will ever terminate. To circumvent this mathematical impossibility, algorithms like Raft rely on partial synchrony. They use timeouts and randomized delays to ensure progress, accepting that the system might temporarily halt during severe network disruptions but will eventually recover.
If a network partition occurs, dividing the servers into isolated groups that cannot communicate with one another, the system must prevent a split-brain scenario. In a split-brain failure, different isolated groups might independently elect their own leaders and commit conflicting data, permanently corrupting the replicated state. Raft solves this problem by enforcing a strict quorum requirement for all operations. A quorum is defined as a simple majority of the voting servers in the cluster. For a cluster of N servers, a quorum requires floor(N/2) + 1 servers.
Raft guarantees that only one leader can be elected per term and that a log entry is only considered committed when it has been successfully replicated to a quorum of servers. Because any two quorums in a static cluster must overlap by at least one server, it is mathematically impossible for two different leaders to be elected simultaneously or for two conflicting logs to be committed. The overlapping node acts as the tiebreaker, ensuring that the new leader is aware of the decisions made by the previous leader.
Raft is designed specifically for crash-fault tolerance. It assumes a non-Byzantine failure model, meaning servers may fail by stopping or crashing, and networks may delay or drop messages, but servers do not act maliciously or send intentionally corrupted data. It can tolerate the failure of a minority of servers. For example, a cluster of five servers can continue to operate normally even if two servers fail. If a quorum cannot be reached, the system halts and refuses to process new client requests. This behavior prioritizes data consistency over availability, aligning with the constraints outlined in the CAP theorem[10].
Mechanism and Operation
Raft decomposes the consensus problem into three relatively independent subproblems: leader election, log replication, and safety.[23] The algorithm dictates exactly how servers transition between states, how they divide time into logical terms, and how they communicate using a small set of Remote Procedure Calls (RPCs).
Server States and Terms
At any given time, a Raft server is in one of three distinct states: Leader, Follower, or Candidate. In normal operation, there is exactly one Leader, and all other servers are Followers. Followers are entirely passive. They issue no requests on their own but simply respond to RPCs from Leaders and Candidates. The Leader handles all client requests. If a client contacts a Follower, the Follower redirects the client to the current Leader. The Candidate state is a transitional phase used exclusively to elect a new Leader when the previous Leader fails.
Raft divides time into arbitrary-length logical units called terms. Terms are numbered with consecutive integers. Each term begins with an election, in which one or more Candidates attempt to become the Leader.[24] If a Candidate wins the election, it acts as the Leader for the rest of that term.[24] In some situations, an election will result in a split vote where no Candidate achieves a quorum. In this case, the term will end with no Leader, and a new term (with a new election) will begin immediately.
Terms act as a logical clock in Raft. Every server stores its current term number, and this number is included in every RPC sent between servers. If a server receives an RPC containing a term number higher than its own, it immediately updates its current term and transitions to the Follower state. This mechanism allows servers to detect obsolete information, such as a Leader that was isolated during a network partition and has since been replaced. If a server receives an RPC with a term number lower than its own, it rejects the request outright.
Leader Election
Raft uses a heartbeat mechanism to trigger leader election. When servers start up, they begin as Followers. A server remains in the Follower state as long as it receives valid RPCs from a Leader or Candidate. Leaders send periodic heartbeats to all Followers to maintain their authority. In Raft, a heartbeat is simply an AppendEntries RPC that carries no log data.
If a Follower receives no communication over a designated period called the election timeout, it assumes there is no viable Leader and begins an election to choose a new one. To begin an election, a Follower increments its current term number and transitions to the Candidate state. It then votes for itself and issues RequestVote RPCs in parallel to each of the other servers in the cluster.[25]
The RequestVote RPC includes the Candidate's current term, its server ID, the index of its last log entry, and the term of its last log entry. A Candidate wins an election if it receives explicit votes from a majority of the servers in the full cluster for that specific term.[25] Each server will vote for at most one Candidate in a given term, on a strict first-come-first-served basis. This voting process is subject to a safety restriction regarding the completeness of the Candidate's log, which ensures that a server with missing committed entries cannot become Leader. Once a Candidate wins an election, it becomes the Leader and immediately begins sending heartbeats to all other servers to establish its authority and prevent new elections.
To prevent split votes from repeating indefinitely, Raft uses randomized election timeouts. The timeouts are chosen randomly from a fixed interval, typically between 150 and 300 milliseconds. This randomization ensures that servers rarely time out at the exact same moment. Usually, one server will time out first, transition to the Candidate state, broadcast RequestVote RPCs, and win the election before any other server reaches its timeout threshold. The message complexity for a leader election is O(N) messages per candidate per term (time complexity is measured in time, not messages), where N is the number of servers in the cluster.
Log Replication
Once a Leader has been elected, it begins servicing client requests. Each client request contains a specific command to be executed by the replicated state machines. The Leader appends the command to its local log as a new entry. It then issues AppendEntries RPCs in parallel to each of the other servers to replicate the entry across the cluster. When the entry has been safely replicated to a quorum of servers, the Leader applies the entry to its own state machine and returns the result of that execution to the client. The entry is now considered committed.
The AppendEntries RPC is the primary workhorse of the Raft protocol. It contains the Leader's term, the Leader's ID, the log entries being sent, and the Leader's current commit index. Critically, it also contains two variables used for consistency checking: prevLogIndex and prevLogTerm. These variables represent the index and term of the log entry immediately preceding the new entries being sent.
When a Follower receives an AppendEntries RPC, it first checks if the Leader's term is less than its own current term. If so, it rejects the request. It then checks if its local log contains an entry at prevLogIndex whose term matches prevLogTerm. If it does not find a match, it rejects the request. This rejection prompts the Leader to decrement the index and retry. If the Follower does find a match, it deletes any existing conflicting entries in its log, appends any new entries, and updates its local commit index to match the Leader's commit index.
To manage this process efficiently, the Leader maintains two arrays in memory: nextIndex and matchIndex. The nextIndex array stores the index of the next log entry the Leader will send to each Follower. When a Leader first assumes power, it initializes all nextIndex values to the index just after the last one in its log. If a Follower rejects an AppendEntries RPC due to a log inconsistency, the Leader decrements that Follower's nextIndex and retries the RPC. Eventually, the nextIndex will reach a point where the Leader and Follower logs match. At this point, the AppendEntries RPC will succeed, overwriting any conflicting data on the Follower and bringing its log into perfect synchronization with the Leader. The matchIndex array tracks the highest log entry index known to be successfully replicated to each Follower, which the Leader uses to calculate the global commit index.
If Followers crash or run slowly, or if network packets are lost, the Leader retries AppendEntries RPCs indefinitely. It will continue retrying even after it has responded to the client, ensuring that all Followers eventually store all committed log entries. The message complexity for log replication is O(N) messages per log entry, because the Leader must send an RPC to every Follower. The space complexity is O(L) per server, where L is the total number of entries in the log.
Safety Properties
Raft guarantees five specific safety properties to ensure the replicated state machine executes commands in the exact same order on all servers.
- Election Safety: At most one Leader can be elected in a given term.
- Leader Append-Only: A Leader never overwrites or deletes entries in its own log; it only appends new entries.
- Log Matching: If two logs contain an entry with the same index and term, then the logs are identical in all entries up through that given index.
- Leader Completeness: If a log entry is committed in a given term, then that entry will be present in the logs of the Leaders for all higher-numbered terms.
- State Machine Safety: If a server has applied a log entry at a given index to its state machine, no other server will ever apply a different log entry for that same index.
The Leader Completeness property is the most critical for ensuring data integrity, and it is enforced during the leader election phase. The RequestVote RPC includes the lastLogIndex and lastLogTerm of the Candidate. When a server receives a RequestVote RPC, it compares the Candidate's log information with its own. A server will reject a vote request if its own log is more up-to-date than the Candidate's log.
Raft defines "more up-to-date" by comparing the terms of the last entries. If the logs end with different terms, the log with the later term is considered more up-to-date. If the logs end with the same term, whichever log is longer is considered more up-to-date. Because a log entry must be replicated to a majority of servers to be committed, and a Candidate must receive votes from a majority of servers to win an election, every successful election must involve at least one server that contains all committed entries. The voting rules guarantee that this server will only grant its vote to a Candidate whose log is at least as up-to-date as its own, thereby ensuring that the new Leader possesses all previously committed data.
Cluster Membership Changes
In real production systems, the cluster configuration occasionally needs to change. Administrators may need to replace failed machines, upgrade hardware, or alter the degree of replication. If all servers were to switch from an old configuration to a new configuration simultaneously, the system would be safe. However, in a distributed system, it is impossible to ensure that all nodes transition at the exact same time. If nodes transition independently, the cluster could temporarily split into two independent majorities, allowing two different leaders to be elected for the same term.
Raft supports automated, safe configuration changes using a two-phase approach called joint consensus. During a configuration change, the cluster transitions through a joint state where both the old and new configurations must agree on all decisions. The Leader first proposes a transitional log entry containing both the old and new configurations (often denoted as C_old,new). Once this entry is appended to a server's log, that server immediately begins using the joint configuration for all future decisions.
While the cluster is in the joint consensus state, any new leader must be elected by a majority of the old configuration and a separate majority of the new configuration. After this joint configuration entry is committed, a second log entry containing only the new configuration (C_new) is proposed and committed. Once C_new is committed, the old servers can safely step down or be removed. This two-phase process mathematically prevents the cluster from splitting into two independent majorities during the transition.
In his later dissertation, Ongaro introduced a simplified membership change protocol that avoids the complexity of joint consensus. This simplified approach restricts configuration changes to adding or removing a single server at a time.[26] Because adding or removing one server cannot result in two disjoint majorities, the cluster can safely transition directly from the old configuration to the new one without a joint consensus phase. Most modern Raft implementations utilize this single-server change optimization.
Log Compaction
As a Raft cluster operates, the log grows continuously. If left unchecked, the log would eventually consume all available storage memory and take an unacceptably long time to replay upon a server restart. Raft uses snapshotting as its primary mechanism for log compaction.
Each server independently takes a snapshot of its current state machine state, writes it to persistent storage, and discards all log entries up to that point. The snapshot includes the raw state machine data, as well as the index and term of the last included log entry. This metadata is required to maintain the Log Matching property for subsequent AppendEntries RPCs. Snapshotting bounds the space complexity of the log and ensures fast recovery times after a crash.
Occasionally, a Follower might fall so far behind that the Leader has already discarded the specific log entries the Follower needs to catch up. In this scenario, the Leader cannot use the standard AppendEntries RPC. Instead, the Leader must send its current state machine state directly to the Follower. It accomplishes this via a specialized InstallSnapshot RPC. The InstallSnapshot RPC transmits the snapshot data in chunks. When a Follower receives a complete snapshot, it discards its entire existing log and replaces its state machine state with the data from the snapshot. The time complexity of this operation depends entirely on the size of the state machine, but it saves the space complexity of keeping an infinitely growing log on the Leader.
Discovery and History
Before Raft, the dominant consensus algorithm was Paxos. Paxos was introduced by Leslie Lamport in a 1989 technical report and later published formally in 1998 as "The Part-Time Parliament"[11]. Paxos provided a mathematically rigorous solution to distributed consensus and became the theoretical foundation for highly available systems like Google's Chubby lock service[12]. Another early consensus protocol, Viewstamped Replication[13], was developed independently by Brian Oki and Barbara Liskov in 1988, offering a more leader-centric approach similar to what Raft would eventually adopt. In 2011, Yahoo! Research published the Zab protocol[14], which powered Apache ZooKeeper and explicitly separated leader election from atomic broadcast.
Despite these significant academic advances, Paxos remained the standard taught in universities and implemented in industry. However, Paxos was widely considered opaque and exceptionally difficult to understand. The gap between the single-decree Paxos algorithm (which agrees on a single value) and Multi-Paxos (which agrees on a continuous log of values) left many critical implementation details completely unspecified. Even after Lamport published a simplified explanation titled "Paxos Made Simple"[4] in 2001, the algorithm remained notoriously difficult to translate into a practical, working system. Implementers frequently had to invent unverified extensions to handle real-world requirements like log compaction, client interaction, and cluster membership changes.
In 2013, Diego Ongaro, a Ph.D. student at Stanford University, and his advisor, John Ousterhout, set out to design a new consensus algorithm with understandability as its primary objective. They sought to create a protocol that was as efficient and reliable as Paxos but structured in a way that average software engineers could comprehend and implement without introducing subtle, catastrophic bugs.
Ongaro and Ousterhout published their findings in the 2014 USENIX Annual Technical Conference paper titled "In Search of an Understandable Consensus Algorithm"[2]. To prove their claims regarding understandability, the authors conducted user studies with students at Stanford and other universities. The studies demonstrated that students were able to answer questions about Raft significantly better than they could answer questions about Paxos after equal amounts of study time. The paper won the Best Paper Award and immediately gained traction in the distributed systems community. Ongaro further expanded on the algorithm in his 2014 Ph.D. dissertation, "Consensus: Bridging Theory and Practice"[3], which detailed the mechanisms for client interaction, log compaction, and the simplified single-server membership change protocol.
Following its publication, Raft saw rapid adoption and further academic refinement. In 2016, Heidi Howard, a researcher at Cambridge University, published "Flexible Paxos: Quorum intersection revisited"[15]. Howard demonstrated that the strict majority quorum requirement in Paxos and Raft could be safely relaxed. Her work showed that as long as the quorum used for leader election intersects with the quorum used for log replication, the system remains safe. This discovery allowed for "Flexible Raft" implementations that optimize performance by requiring fewer nodes to acknowledge log replication, at the cost of requiring more nodes to participate in leader elections.
Important Variants
As Raft transitioned from an academic proposal to an industry standard, several variants and extensions were developed to address specific operational challenges in large-scale deployments.
Pre-Vote Extension
One vulnerability in the original Raft specification involves partitioned nodes. If a Follower is disconnected from the cluster due to a network partition, it will not receive heartbeats. It will repeatedly time out, increment its term number, and broadcast RequestVote RPCs into the void. When the partition eventually heals, this node will rejoin the cluster with an artificially high term number. Upon receiving a message from this node, the current Leader will see the higher term, step down, and revert to a Follower, causing an unnecessary disruption in availability. The Pre-Vote extension[16], detailed in Ongaro's dissertation, solves this by requiring a Candidate to check if it can win an election before actually incrementing its term. The Candidate sends a PreVote RPC to other nodes, and only transitions to a full Candidate state if a majority of nodes indicate they would grant their vote.
Multi-Raft
In large-scale distributed databases, a single Raft group can become a severe performance bottleneck because all writes must be processed sequentially by a single Leader. To scale horizontally, systems employ a Multi-Raft architecture. The dataset is partitioned into smaller segments, often called ranges or shards, and an independent Raft consensus group manages each segment. This allows the system to distribute leadership across many different physical nodes, parallelizing write operations across the cluster. This architecture is heavily utilized by distributed storage engines like TiKV.
Byzantine Raft
The standard Raft algorithm is designed strictly for crash-fault tolerance and assumes that nodes will not send malicious or corrupted messages. In environments where nodes might be compromised by attackers, Byzantine Fault Tolerant consensus is required. Researchers have developed Byzantine variants of Raft[17], which modify the leader election and log replication phases to require cryptographic signatures and larger quorums to tolerate malicious actors.[27] These variants ensure that a compromised Leader cannot forge log entries or manipulate the election process.
Flexible Raft
Building on Heidi Howard's research, Flexible Raft implementations adjust the quorum sizes for different phases of the algorithm. By reducing the number of acknowledgments required for the AppendEntries RPC, systems can decrease write latency and increase overall throughput. To maintain the necessary intersection guarantee, these systems must simultaneously increase the quorum size required for the RequestVote RPC. This tradeoff is highly advantageous in systems where log replication happens constantly but leader elections are rare.
KRaft
In the Apache Kafka ecosystem, the reliance on an external ZooKeeper cluster for metadata management became an operational burden. To resolve this, the Kafka community developed KRaft, detailed in KIP-500[18]. KRaft is an event-driven variant of the Raft protocol integrated directly into Kafka brokers. It allows Kafka to manage its own metadata quorum, removing the ZooKeeper dependency entirely and allowing clusters to scale to millions of partitions while maintaining strict metadata consistency.
Real-World Applications
Raft's emphasis on understandability and its clear, unambiguous specification led to rapid and widespread adoption across the software industry. It is now the default consensus mechanism for a vast array of distributed systems, from configuration stores to global databases.
The most prominent implementation of Raft is etcd, a distributed key-value store originally developed by CoreOS. etcd uses Raft to manage its replicated log and serves as the primary datastore for Kubernetes, the industry-standard container orchestration platform. Every Kubernetes cluster relies on an etcd Raft group to store cluster state, configuration data, and secrets, making Raft an essential component of modern cloud infrastructure. The etcd Raft library is highly modular and is embedded in many other open-source projects.
HashiCorp Consul, a widely used service networking and discovery platform, also relies heavily on Raft. Consul uses Raft to maintain a consistent catalog of services and nodes across a datacenter. The Consul servers form a Raft quorum to ensure that service discovery queries return consistent, up-to-date information even during severe network disruptions.
Distributed SQL databases utilize the Multi-Raft variant to achieve both high availability and horizontal scalability. CockroachDB, a cloud-native distributed database, divides its data into small ranges and uses a separate Raft consensus group for each range. This allows CockroachDB to survive machine failures without losing data or violating ACID transaction guarantees. Similarly, TiKV, the distributed storage engine backing the TiDB database, uses a Multi-Raft architecture to manage data replication and consistency across thousands of nodes.
Message brokers have also adopted Raft to improve reliability and data safety. RabbitMQ introduced "Quorum Queues"[19] in version 3.8 as a modern replacement for its legacy mirrored queues. Quorum queues use the Raft algorithm to replicate messages across multiple broker nodes, providing stronger data safety guarantees and preventing message loss during network partitions. Redpanda, a Kafka-compatible streaming platform, uses Raft natively for both metadata and data replication, bypassing the need for an external consensus system and achieving high throughput with low latency.
Even systems that do not implement the full Raft log replication protocol often borrow its leader election mechanics. MongoDB[20], a popular NoSQL document database, redesigned its replica set election protocol in version 3.2 to closely mirror Raft's leader election. This redesign improved failover times and ensured stricter consistency during network partitions. Graph databases like Neo4j[21] and columnar stores like Apache Kudu also implement Raft to manage cluster topology, leader election, and data replication.
Significance and Tradeoffs
The primary significance of Raft is its demystification of distributed consensus. Before Raft, implementing a fault-tolerant replicated state machine was considered an esoteric task fraught with edge cases and theoretical complexities. By providing a clear, modular algorithm and prioritizing understandability above all else, Raft democratized the development of reliable distributed systems. Its widespread adoption has standardized how the industry handles coordination, configuration management, and service discovery.
The strong leadership model in Raft simplifies the data flow significantly. Because all log entries flow in a single direction from the Leader to the Followers, resolving conflicts is straightforward. The Leader's log is always considered the absolute truth, and Followers simply overwrite their conflicting data to match the Leader. This design choice makes the algorithm easier to reason about and simplifies the implementation of the AppendEntries RPC.
However, this strong leadership model introduces specific tradeoffs. The Leader can become a severe performance bottleneck, as it must process every write request and broadcast it to the entire cluster. In high-throughput environments, the CPU and network bandwidth of the Leader node often limit the overall capacity of the system. While Multi-Raft architectures mitigate this by partitioning the data, they introduce additional complexity in managing cross-partition transactions. Algorithms like Egalitarian Paxos[22] attempt to solve this bottleneck by allowing any node to process writes, but they do so at the cost of significantly increased complexity.
Serving read requests in Raft also presents a specific challenge. If a Leader responds to a read request using its local state machine without consulting the cluster, it might return stale data if a network partition has isolated it and a new Leader has already been elected elsewhere. To guarantee linearizable reads, the Leader must either exchange heartbeat messages with a quorum before responding to the read, or the system must implement a time-based lease mechanism. Both approaches add latency or complexity to read operations.
Furthermore, Raft is highly sensitive to network latency. Because a log entry must be acknowledged by a quorum of nodes before it is committed, the latency of a write operation is dictated by the round-trip time to the majority of the cluster. In geo-distributed deployments where nodes are spread across multiple continents, this latency can be substantial.
Finally, Raft is strictly a crash-fault tolerant protocol. It is not suitable for decentralized or trustless environments, such as public blockchain networks, where nodes may act maliciously. In such environments, Byzantine Fault Tolerant algorithms or Proof-of-Work mechanisms are required. Within the confines of trusted, private datacenters, however, Raft provides an optimal balance of consistency, fault tolerance, and engineering practicality.
Sources (27)
- Raft consensus algorithm
- replicated log
- purl.stanford.edu: Stanford University
- Microsoft
- etcd
- HashiCorp Consul
- CockroachDB
- ACM Digital Library
- ACM Digital Library
- ACM Digital Library
- ACM Digital Library
- Chubby lock service
- ACM Digital Library
- Zab protocol
- "Flexible Paxos: Quorum intersection revisited"
- Pre-Vote extension
- ACM Digital Library
- KIP-500
- "Quorum Queues"
- MongoDB
- Neo4j
- ACM Digital Library
- Jaiteg Singh, S. B. Goyal, Manoj Kumar, Advanced Network Technologies and Computational Intelligence (Springer Nature, 2025)
- Chunxiao Xing, Xiaoming Fu, Yong Zhang, Web Information Systems and Applications (Springer Nature, 2021)
- Leonard Barolli, Fang-Yie Leu, Tomoya Enokido, Advances on Broadband and Wireless Computing, Communication and Applications (Springer, 2018)
- Liang Yan, Haibin Duan, Yimin Deng, Advances in Guidance, Navigation and Control (Springer Nature, 2025)
- Carlos Toro, Wei Wang, Humza Akhtar, Implementing Industry 4.0 (Springer Nature, 2021)