The Raft consensus algorithm is designed for understandability, but its formal verification reveals subtle edge cases in leader transition.
Election Safety Invariant
The core safety property of Raft is that at most one leader can be elected in a given term.1 Safety invariants are checked for every reachable state in the model.
// TLA+ Specification Snippet: Election Safety Invariant
ElectionSafety ==
\A t \in Terms :
Cardinality({i \in Servers : state[i] = Leader /\ currentTerm[i] = t}) <= 1
Using the TLC model checker, we can verify this invariant for small cluster sizes (N=3, N=5).
Log Matching and Persistence
A more complex property is Log Matching: if two logs contain an entry with the same index and term, then the logs are identical.
Liveness and Temporal Logic
While safety is straightforward to prove, liveness requires assumptions about temporal properties.2 TLA+ uses temporal logic to express “eventually” properties.