Distributed-systems simulator
Paxos Consensus
Single-decree Paxos. Five nodes form one cluster with a quorum of 3. Node 0 proposes "apple" and node 1 proposes "banana" at the same simulated instant, for the same decree - and the algorithm still guarantees exactly one value is ever chosen.
How to read it: watch the message pump route ballots round by round. The program picks nothing; the ballot numbers and message interleaving decide. A node turns green the round it commits, and the demo then checks byte-for-byte that all five agree.
VERIFICATION: PASS - all 5/5 nodes decided, and every one agrees on "banana" despite the simultaneous race.
| node | IsDecided | DecidedValue |
|---|---|---|
| 0 | True | "banana" |
| 1 | True | "banana" |
| 2 | True | "banana" |
| 3 | True | "banana" |
| 4 | True | "banana" |
Node 0 proposed "apple" and lost the race, yet it too commits "banana" - Paxos never lets two values be chosen for one decree.
Message pump transcript
Single-Decree Paxos -- 5-node in-process consensus demo
OnlyCSharp.ComputerNetworks.DistributedSystems.Paxos.SingleDecreePaxos
=======================================================================
Nodes 0-4 form one cluster (quorum = 3 of 5). Node 0 proposes "apple" and
node 1 proposes "banana" AT THE SAME TIME, for the SAME single decree.
Paxos guarantees at most one value is ever chosen. Watch the race:
node 0: Propose("apple")
node 1: Propose("banana")
round 1: routed 10 message(s) -- decided 0/5
round 2: routed 10 message(s) -- decided 0/5
round 3: routed 10 message(s) -- decided 0/5
round 4: routed 10 message(s) -- decided 0/5
round 5: routed 5 message(s) -- decided 5/5 [node 0 DECIDED 'banana'] [node 1 DECIDED 'banana'] [node 2 DECIDED 'banana'] [node 3 DECIDED 'banana'] [node 4 DECIDED 'banana']
Message pump finished after 5 round(s). Final state:
node 0: IsDecided=True DecidedValue="banana"
node 1: IsDecided=True DecidedValue="banana"
node 2: IsDecided=True DecidedValue="banana"
node 3: IsDecided=True DecidedValue="banana"
node 4: IsDecided=True DecidedValue="banana"
=======================================================================
Two proposers raced for the same decree: node 0 proposed "apple",
node 1 proposed "banana".
Value actually chosen by the algorithm: "banana"
VERIFICATION: PASS -- all 5/5 nodes decided, and every one of them agrees on "banana" despite the simultaneous race.