20 Raft 1 Commit

Raft

  • Distributed Consensus over a RSM
  • A quorum (majority of nodes in a cluster) protocol
  • Leader Election
  • Log
  • No CFG, no Primary Server (No single point of failure)

Client Interaction

  1. Client can contact any server in the raft cluster
  2. The server points client to the leader
  3. Client must submit operations to the leader, then await response
  4. If server says 'OK', operation will not be lost, guarantees strong consistency

Raft Log

  • Contains every operation to replicate the system (RSM)
  • Contains term (Era/Yuan Nian, guarantees only 1 leader at a give time), and index (position of entry in log)

Application state: current data or situation inside the program that’s using Raft.

Process

  1. Client submit operation
  2. Leader saves operation to Log
  3. Leader propagate new log entry to all other server via AppendEntries
  4. If the majority responded to leader, commit and respond to client OK

Commit Index

  • Kept by all servers (leader & follower)
  • Keeps track of all committed entries on the server
  • Updated by the leader (when majority has concensus, which means that this data could never be lost)
  • Leader propagates commitindex regularly via AppendEntry

Pasted image 20251026010154.png

Even if one server fails, majority still agrees
Pasted image 20251026010238.png