A Python distributed key-value store using the Raft consensus algorithm.
- Leader election, log replication, commit/apply
- HTTP API:
GET /kv/{key},PUT /kv/{key} - Snapshots when log exceeds threshold
- InstallSnapshot for lagging followers
- HTTP redirect to leader when writing to follower
Run a 3-node cluster (3 terminals):
# Terminal 1
python main.py --node-id A --port 50051 --http-port 8080 \
--peers "B=localhost:50052,C=localhost:50053" \
--cluster-http-urls "A=http://localhost:8080,B=http://localhost:8081,C=http://localhost:8082"
# Terminal 2
python main.py --node-id B --port 50052 --http-port 8081 \
--peers "A=localhost:50051,C=localhost:50053" \
--cluster-http-urls "A=http://localhost:8080,B=http://localhost:8081,C=http://localhost:8082"
# Terminal 3
python main.py --node-id C --port 50053 --http-port 8082 \
--peers "A=localhost:50051,B=localhost:50052" \
--cluster-http-urls "A=http://localhost:8080,B=http://localhost:8081,C=http://localhost:8082"Then:
curl -X PUT http://localhost:8080/kv/hello -d 'world'
curl http://localhost:8081/kv/hello- Python 3.11+
- uv (or pip) for dependencies
uv sync # or: pip install -e .