An implementation of the Raft consensus algorithm in Go, including leader election, log replication, persistence, and snapshot-based log compaction.
This project was implemented following the MIT 6.824 Distributed Systems Raft labs.
- MIT 6.824: https://pdos.csail.mit.edu/6.824/
- Raft Paper: https://raft.github.io/raft.pdf
- Visualization: https://raft.github.io/
- Full Raft implementation: leader election, log replication, and safety checks.
- Durable state via persistence and snapshotting for log compaction.
- Replicated key/value store on top of Raft.
- Sharded key/value store with a shard controller service.
- MapReduce lab code and harness for integration testing.
src/raft: Raft core (election, append entries, persistence, snapshots).src/kvraft: Replicated key/value server built on Raft.src/shardctrler: Shard controller for reconfiguration.src/shardkv: Sharded key/value store built on Raft.src/labrpc: Simulated RPC/network layer used by the labs.src/labgob: Lab-specific encoder/decoder utilities.src/porcupine: Linearizability checker used by tests.src/mr,src/mrapps,src/main: MapReduce implementation and test drivers.
This repo is organized as the MIT 6.5840 module (src/go.mod). From the repo root:
cd src
go test ./raftRun tests by package (from src/):
go test ./raft
go test ./kvraft
go test ./shardctrler
go test ./shardkvRun everything:
go test ./...The MapReduce harness lives in src/main. A quick smoke test:
cd src/main
bash test-mr.sh- This code targets the MIT 6.824 lab environment and is not production-ready.
- The RPC layer and persistence are provided by lab utilities to focus on Raft logic.