Consensus, Replicated Logs and Coordination
Consensus is learned through invariants and adversarial schedules. A working happy-path election is insufficient until committed entries survive partitions, restarts, snapshots and leadership changes.
Section 5 of 9 · 14 units · about 71 hours
By the end you can Preserve consensus safety across loss, duplication, reordering, partitions, crashes, restarts and snapshots, minimize one non-progress history, and prevent stale clients from committing protected effects.
Units
- State-machine replication and safety versus liveness3h
- Terms and epochs, follower, candidate and leader states and randomized election timeouts6h
- The RequestVote freshness rule, split votes, pre-vote and leadership transfer4h
- The AppendEntries consistency check and the log matching property6h
- Conflict truncation, log repair and slow-follower backtracking5h
- Majority commitment, the current-term restriction, committed-entry preservation and leader completeness5h
- Ordered exactly-once application, persistent term, vote and log state, and crash and restart6h
- Leader partitions, stale messages and fenced locks4h
- Snapshot creation, log compaction and snapshot installation6h
- Membership change safety and joint consensus5h
- Linearizable read paths, ReadIndex and lease reads8h
- A deterministic message scheduler with seeded random schedules4h
- Invariant checks after every transition and failure-history minimization5h
- Election, commit, recovery, message and snapshot costs and availability versus safety diagnosis4h
Build it
Mini project · about 18 to 24 hours
Consensus log with durable authority and replayable counterexamples
Replace loglab's promotion controller with a reduced Raft core in consensus/, retaining the existing protocol, storage and history boundaries. Establish timing-free safety before measuring progress on your machine, and keep public lab evidence distinct from actual storage recovery and external-resource fencing.
- 1Build the Raft transition core with an invariant ledger, fault model and acceptance, persistence, commit, apply and reply events. Check elections, freshness, prefix matching, backtracking and current-term commitment against the Raft paper and MIT 6.5840 Lab 3A/3B; retain proofs and adversarial traces.
- 2Connect durable term, vote and log state to
storage/; recover application, applied boundary and client deduplication together. Add snapshots with index, term and recoverable state; check against single-node replay. Retain publication-crash, partial-snapshot, stale-install and retry regressions separately from MIT Lab 3C/3D results. - 3Implement quorum-confirmed reads after current-term commitment, with fresh round identity and an application barrier for leader and follower service. Check partitioned old leaders, old-round replies and lagging application with the register oracle; retain histories alongside MIT Lab 4A/4B's logged-read baseline and lease-assumption derivation.
- 4Issue committed lock tokens and atomically persist resource fencing with effects; test stale holders across restart and new-owner activation. Independently enumerate joint quorums and trace a transition crash against the paper's activation rules; retain both counterexamples, keeping full reconfiguration optional and the core fixed-membership.
- 5Extend
net/with explicit timer, message and durable-write completions. Check vote-before-reply ordering against the persistence contract; retain seeded loss, duplication, reordering, partition and restart campaigns plus seed-independent event replay. Include healing, split-vote, pre-vote and transfer traces checked against the thesis's rules without requiring optional extensions. - 6Monitor every transition using independent historical election, committed-prefix and application ledgers that survive compaction. Plant a double-vote bug and minimize its safety witness, then minimize a bounded stall preserving its request, reachable majority and healing assumptions; retain replay regressions and classify each predicate separately.
- 7After deterministic gates, run repeated matched baseline, leader-partition, restart/catch-up and snapshot campaigns on your machine. Validate counters against hand-counted traces; retain versions, workloads, durability settings, raw histories, invariant verdicts, election/commit/apply/reply distributions, throughput, message/byte costs, snapshot costs, timeouts and incomplete recoveries, distinguishing logical from measured time.
What you hand in
- The
consensus/core, durable adapter, read barriers, fenced-resource fixture and explicit assumption and invariant ledger. - Public lab results plus independent
history/checks, storage-crash tests, joint-quorum enumeration and minimized schedules infaults/andtests/. - Raw protocol, storage and snapshot traces with repeated matched measurements and bounded-stall diagnosis in
reports/.
How to check it
- Self-grade with the rubric below
- MIT 6.5840 Spring 2026 Lab 3: Raft, Parts A through D
Retain election, agreement, simulated persistence and snapshot results; keep course-interface adapters or private Go lab solutions separate from language-independent core evidence.
- MIT 6.5840 Spring 2026 Lab 4: key/value service, Parts A and B
Retain logged-read baseline results; these do not replace your fresh-quorum read-barrier, durable-publication or fencing tests.
How it's graded
Durable replicated safety
Pass: Your independent ledgers validate elections, matching prefixes, preserved commitments and ordered application; replay-oracle tests cover storage publication, snapshots and client deduplication beyond the public lab's simulated persistence.
Great: The planted bug fails before repair and passes afterward on the same minimized schedule; historical monitors still detect violations hidden by step-down or compaction.
Authority and read boundaries
Pass: Your register checker validates read histories despite stale rounds and application lag; resource tests enforce durable fencing after activation. Independent quorum enumeration rejects union-majority shortcuts in the joint-transition trace.
Great: Leader and follower reads share tested barriers; the defense distinguishes grant from resource activation, states lease assumptions, and preserves configuration state in optional reconfiguration recovery tests.
Replay and diagnosis
Pass: Recorded events replay without random selection; reduced safety and bounded-stall predicates remain distinct. Hand-counted counters validate repeated matched measurements with named versions, workload, timeouts, costs and invariant verdicts.
Great: The stall retains environmental preconditions and an explained missing prerequisite; reports separate simulated time from measured distributions and retain incomplete recovery rather than hiding it.
Resources
- MIT 6.5840 - Lab 3 RaftMIT PDOS
Complete Spring 2026 Lab 3A to 3D in order with the extended Raft paper, keeping the official tests (
make RUN="-run 3A" raft1and so on). The labs leave out membership change (Section 6) and lease reads, so those units use the paper. Then add deterministic message schedules, durable crash injection, state-machine invariants and minimized traces in your own harness. - In Search of an Understandable Consensus AlgorithmDiego Ongaro and John Ousterhout
Read the extended Raft paper alongside each lab part. Maintain a one-page invariant ledger for election safety, log matching, leader completeness, state-machine safety and membership change.
- Consensus: Bridging Theory and Practice (Ongaro, 2014)Stanford University
Use the thesis where the paper and the labs stop: Section 3.10 (leadership transfer), Chapter 4 (single-server membership changes, catching up new servers, removing the leader, disruptive servers, joint consensus), Section 6.4 (ReadIndex and lease-based read-only queries) and Section 9.6 (pre-vote).
- DDIA 2e - Chapter 10 Consistency and ConsensusMartin Kleppmann and Chris Riccomini
Read consensus, total-order broadcast, linearizable storage and coordination sections after the first Raft implementation. Compare abstraction boundaries rather than memorizing protocol names.
- Paxos Made Simple (Lamport, 2001)Leslie Lamport
Read single-decree Paxos (prepare and accept phases, the safety argument) and the closing sketch of a replicated state machine, then map ballots to Raft terms. It is single-decree; a log needs the Multi-Paxos ordering layer.
- Impossibility of Distributed Consensus with One Faulty Process (Fischer, Lynch and Paterson, 1985)MIT Theory of Distributed Systems group
Read the model and the main theorem. It covers deterministic asynchronous consensus with one crash and says nothing against randomized or timeout-based protocols, which is why Raft needs timeouts only for liveness.
- ZooKeeper: Wait-free Coordination for Internet-scale Systems (Hunt et al., 2010)USENIX ATC (MIT 6.5840 copy)
Read the ordering guarantees, sessions and the Zab-based implementation, as MIT Lecture 9 does. Writes are linearizable; reads are served locally and may be stale unless preceded by
sync. - The Chubby Lock Service for Loosely-Coupled Distributed Systems (Burrows, 2006)Google (author copy)
Read the design sections on locks, sequencers and lock-delay and the Paxos-backed cell. Its locks are advisory; sequencers are how a resource rejects a stale holder.
- etcd v3.7 API Guarantees and the etcd-io/raft Libraryetcd Authors
Read the API guarantees page (strict serializability and revisions, linearizable versus serializable reads, leases, watch guarantees, uncertain outcomes after a timeout) and the raft library README (https://github.com/etcd-io/raft) for how a production library splits the protocol from storage and network.
- Cambridge Concurrent and Distributed Systems Notes (Kleppmann) - Consensus and RaftUniversity of Cambridge (Martin Kleppmann)
Use Chapter 6 (consensus, FLP and Raft election, replication and commitment) as a second explanation of the protocol, and work Exercise 18 (three Raft logs) before Lab 3B.
- How to Do Distributed Locking (Kleppmann, 2016) - Fencing TokensMartin Kleppmann
Reread the fencing-token section when you add a lock or lease on top of your log: the term or log index becomes the token, and the resource must reject an older one.
- HLD Handbook - Consensus ProtocolsHLD Handbook
Use Part 3 consensus for visual review of Raft and Multi-Paxos after the invariant ledger is complete. Check any simplified production claim against primary papers or official system documentation.
- MIT 6.5840 - Lab 4 KV RaftMIT PDOS
Implement the key-value layer only after Raft invariants pass. Focus on client identity, duplicate suppression, snapshot state and request completion across leadership change.
- DSLabs - Lab 3 PaxosUniversity of Washington (Ellis Michael)
Labs are Java 21 message-passing state machines tested on an emulated network and by model-checking search tests that print a minimal violating trace; run them with the
run-tests.pyscript and its--laband--partoptions. Lab 3 is a Paxos-replicated service: compare its ballots, quorums and log slots with your Raft terms and indexes, and study how its search tests find and minimize violating schedules. - Replicated Log and Stream Processor - Consensus SliceRoadmap-Final
Add the reduced replicated log, persistence, snapshots and fenced ownership. Preserve a seeded campaign for partition, restart, stale leader, conflicting log and snapshot mismatch.
- TLA+ Video Course - Transaction Commit and Paxos CommitLeslie Lamport
Watch lectures 5 to 7 (Transaction Commit, Two-Phase Commit, Paxos Commit) only after implementing Raft, check the course corrections page and run TLC on the matching specifications in the TLA+ Examples repository (https://github.com/tlaplus/Examples/tree/6a7b26a31c1a6aeec789b455e9bbfa3b3ad2728f/specifications/transaction_commit). Save the full TLA+ route for DS-9.
- Building Distributed Systems - The Elector and The ConsensusBuild Distributed Systems
Only the first three tasks of each track are free: in The Elector, node states, heartbeats and randomized timeouts; in The Consensus, log replication, log matching and commitment. Tasks are graded in the browser after login, so treat a pass as a drill and keep your local harness as the evidence.