systems · sub-star
nexus_cluster
raft consensus from the paper: elections, log replication, a replicated key-value store.
readme
The Raft consensus algorithm in Python, running as five processes over TCP: leader election, log replication, and a key-value store that survives the leader being killed. The algorithm is a state machine with no I/O at all, so the same file runs behind asyncio sockets, inside a deterministic simulation that checks Raft’s safety properties every 5 ms, and in the browser under Pyodide.
artifact
simulated cluster: heartbeats, an election timeout, and a new leader.
signal log
- figure 2 of the paper, from scratch: votes only for candidates whose log is at least as up to date, step-down on any higher term, AppendEntries consistency checks, and truncation only at a real conflict.
- commits only by counting replicas of an entry from the current term, and appends a no-op on election so inherited entries commit without waiting for a client write.
- a simulation with message loss, reordering, crashes and partitions asserts election safety, log matching, leader completeness and state machine safety after every step, across 40 chaotic seeds.
- the tests were checked by deleting each of eight safety rules in turn. the random simulation caught six; the other two needed hand-built state, and now all eight fail a test.
- length-prefixed TCP framing, and every RPC bounded by a timeout, because a partitioned peer neither accepts nor refuses and an unbounded wait stalls the timer meant to detect it.
- kill the leader process and a new leader is elected within a few seconds, with every committed key intact.
built with
PythonRaftasyncioPyodide