Build a Distributed Key-Value Store with Raft in Go (on hashicorp/raft): a Localpane Lab Kit
Build a replicated key-value store in Go, one tested step at a time. You write the state machine, wire three nodes to the hashicorp/raft library, then add replication, exactly-once retries, linearizable reads, an HTTP API, network partitions, snapshots and a benchmark. Every step has a starter with marked TODOs, tests that fail until your code works, plain explanations of the ideas, and hints. One command checks your work. By the end you have run leader elections, crashed and restarted nodes, cut the network and checked recorded histories for linearizability with Porcupine, on your own machine. The complete solution is included.
What's inside
- WORKBOOK.md: 8 steps, each with the goal, key concepts in plain words, where the starter code is, the tests that must pass, hints and a check command
- 8 starter projects (steps/step-01 to step-08): earlier steps solved, the current one stubbed
- The finished solution: about 1,600 lines of Go and 1,200 lines of tests
- 28 graded tests, and 6 tests for the code the kit provides
- check.sh to check one step and everything before it
- A 3-node local cluster script and a status page, with curl commands for partitions
- An in-process benchmark comparing 1 node with 3
The 8 steps:
- Commands and the state machine
- Leader election: wiring a Raft node
- Log replication and commit
- Exactly-once writes and linearizable reads
- The HTTP API
- Fault lab: network partitions
- Snapshots and recovery
- Benchmarks: the price of replication
Who it's for
Go developers who want to understand how a consensus-backed store behaves under failure by building one: backend engineers moving towards distributed systems, people preparing for system-design discussions, and anyone who has read the Raft paper and wants to see it run.
Not for: anyone looking for a production database, or for a from-scratch implementation of the Raft algorithm itself (this kit uses the hashicorp/raft library for consensus and has you build everything around it).
Prerequisites
- Go 1.27 or later; tested on macOS (Apple Silicon). Linux and Windows not yet tested.
- Comfortable with goroutines, channels, interfaces, net/http and Go tests
- No prior Raft knowledge needed
- About 8 to 12 hours
Licence
Single-developer licence: use and modify the code, including in your own products; no redistribution and no public repositories. Free updates within 1.x.
Uses the open-source hashicorp/raft library; not affiliated with or endorsed by HashiCorp.
Refunds: within 14 days of purchase if a file is defective or not as described. Contact me through the store's Contact button. This doesn't affect any rights you have under the law where you live.
Licence summary: payhip.com/u1791141470733132530294/licences