What problem does Raft solve?
Raft solves distributed consensus: how multiple servers agree on the same ordered history of commands even when machines fail or messages are delayed.
Why does Raft need a leader?
A leader simplifies write ordering. Clients send writes to one authority, which reduces ambiguity and makes log replication easier to reason about.
How is a leader elected?
When followers stop hearing heartbeats, one times out, becomes a candidate, increments its term, and asks peers for votes. A majority makes it leader.
Why are election timeouts randomized?
Randomization reduces the chance that multiple followers become candidates simultaneously and repeatedly split the vote.
What is the difference between committed and replicated?
Replicated means followers have received the entry. Committed means Raft guarantees the entry will survive future leadership changes and can be safely applied.
What are the main formulas to remember in Raft?
quorum = floor(N/2) + 1, failure tolerance f = floor((N - 1)/2), and cluster size N = 2f + 1.
Which open source systems use Raft in production?
Examples include etcd, Consul, Nomad, rqlite, YugabyteDB, CockroachDB, Dgraph, TiKV, SwarmKit, Kubernetes through etcd, and Hyperledger Fabric's Raft ordering service.
What exactly triggers a new election?
A follower starts an election when it does not receive a valid heartbeat or AppendEntries before its randomized election timeout expires.
What does a follower do when its election timeout fires?
It increments its term, transitions to candidate, votes for itself, resets its election timer, and sends RequestVote RPCs.
Can a follower vote for more than one candidate in the same term?
No. A server grants at most one vote per term.
How does a candidate become leader?
It becomes leader only after receiving votes from a majority of the current configuration.
What if two candidates start an election at the same time?
They can split the vote. Randomized timeouts make one retry later and usually break the tie.
What happens if a candidate loses the election?
If it sees a valid leader or higher term, it steps down. If nobody wins, it may retry after another timeout.
How does a stale leader get forced to step down?
If it receives an RPC with a higher term, it updates its term and becomes a follower.
Can there be two leaders at once?
Two nodes may temporarily believe they are leader, but only a side with quorum can commit writes. The stale leader steps down after seeing a higher term.
Why does log freshness matter during voting?
Voters reject candidates whose logs are less up to date, helping preserve committed entries.
What if a node has the highest term but a stale log?
Highest term alone is not enough. The candidate still must pass the up-to-date log check.
What happens if the leader is isolated with only one follower in a five-node cluster?
That side has only 2 of 5 nodes and cannot commit. The 3-node majority side can elect a new leader.
What happens to client writes during an election?
Writes may stall or retry until a leader is elected.
Can a candidate append new log entries before winning?
No. It must win leadership before accepting and replicating new client commands.
What if a candidate receives AppendEntries from a valid leader?
It steps down to follower if the leader's term is current or higher.
How do heartbeats relate to leader election?
Heartbeats are empty AppendEntries messages that prevent followers from starting elections.
What happens if heartbeats are delayed but the leader is alive?
Followers may start unnecessary elections, causing leader churn and latency spikes.
What if a follower restarts during an election?
It returns as a follower with persisted term and vote state, then participates based on the latest term it observes.
What if no node can get a majority?
The cluster cannot elect a leader and becomes unavailable for new writes until quorum returns.
How do even-numbered clusters affect elections?
They add cost without improving failure tolerance compared with the next lower odd number and can make ties more likely.
What are the most important election edge cases?
Split votes, stale leaders after partition heal, delayed RPCs from old terms, candidates with stale logs, repeated timeouts, and rejoining nodes seeing higher terms.
How do log matching rules prevent divergence?
Followers only accept new entries if the preceding index and term match their local log.
What is the election restriction?
A candidate must be at least as up to date as the voter to receive a vote.
What makes the Figure-8 scenario famous?
It shows that older-term entries replicated to many nodes are not automatically committed without the correct current-term commit rule.
Can Raft have split-brain?
It can have temporary leader confusion, but not two conflicting committed histories if quorum rules are followed.
What are important Raft edge cases?
Split votes, stale leaders, uncommitted log tails, snapshots, membership changes, and delayed messages.
How does Raft recover a follower that is far behind?
The leader may replay logs or install a snapshot if the missing log range has been compacted.
How does Raft change cluster membership safely?
Through joint consensus, requiring overlapping majorities from old and new configurations during transition.
Why is log compaction part of the real story?
Snapshots keep logs from growing forever and allow far-behind followers to catch up efficiently.
How should I read a leader-election diagram?
Follow missing heartbeat, timeout, candidate transition, RequestVote, and majority decision.
How should I read a replication diagram?
Track the entry from client to leader log, then to followers, then to majority acknowledgment and commit.
How does YugabyteDB use Raft?
Each tablet has its own Raft group, leader, WAL, and followers.
What are tablet leaders in YugabyteDB?
They coordinate writes and replication for one shard of data.
Why does tablet leader distribution matter?
Uneven leadership creates hotspots and poor cluster utilization.
Which Yugabyte tuning areas usually matter?
Election timing, heartbeat timing, load balancing, placement, RPC pressure, WAL throughput, compaction, and remote bootstrap behavior.
Does YugabyteDB use plain textbook Raft?
It is based on production Raft ideas and includes implementation-specific enhancements such as leases and pre-voting behavior.
How can you inspect tablet leadership?
Use cluster UI and metadata views such as yb_tablet_metadata to inspect placement and leadership.
What symptoms suggest Raft instability?
Frequent leader changes, high write tail latency, follower lag, under-replicated tablets, queue growth, and vote bursts.
How do you troubleshoot repeated elections?
Check packet loss, CPU stalls, disk latency, RPC overload, heartbeat tuning, and intermittent isolation.
What production failure scenarios are realistic?
Zone partition, noisy-neighbor CPU starvation, slow fsync, leader concentration, and follower catch-up after outage.
What operational checklist is useful?
Check quorum, leader churn, packet loss, disk latency, CPU starvation, follower lag, leases, and failure-domain placement.
How do you explain Raft to leadership?
Raft picks one safe authority per replicated group and waits for a majority before confirming important changes.
What are management talking points?
Predictable failover, strong consistency, controlled fault tolerance, operational clarity, and lower corruption risk.
Why is Raft important to management?
It adds coordination cost but greatly improves correctness, failover predictability, and confidence during infrastructure failures.