go-store is a simple distributed key-value store built with Go and the Raft consensus algorithm, using the hashicorp/raft library.
- Raft-based consensus: Ensures data consistency and high availability even during node failures.
- Key-Value storage: Supports storing simple string keys and values (internally as byte slices).
- The Raft FSM uses in-memory storage.
- Raft logs and snapshots are persisted using BoltDB.
- gRPC API: Provides gRPC endpoints for cluster management and data operations:
- Add peer (
AddPeer) - Remove peer (
RemovePeer) - Get cluster status (
GetStatus,GetCluster) - Apply data commands (
ApplyCommand)
- Add peer (
- Docker-based deployment & testing: Easily run and test a local Raft cluster with
docker-compose.
- Go (v1.24 or later recommended)
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/<your-username>/go-store.git cd go-store
-
(Optional) Create a
.envfile: You can define environment variables in a.envfile in the root directory. Example:RAFT_DATA_DIR=/tmp/my-raft-data. Defaults are provided indocker-compose.yml. -
Start the cluster with Docker Compose:
docker-compose up --build -d
This spins up a 3-node Raft cluster with
node1bootstrapped as the leader. -
Interact with the gRPC API: Use a tool like
grpcurlto communicate with the cluster via gRPC ports (34001,34002,34003).-
Check leader status (e.g., via node1):
grpcurl -plaintext localhost:34001 api.RaftService/GetStatus
-
Store data using
ApplyCommand: First, identify the leader node and call:grpcurl -plaintext -d '{"type": "SET", "key": "mykey", "value": "myvalue"}' localhost:34001 api.RaftService/ApplyCommandNote: Reads are available via HTTP
GET /key?key=...or gRPCGetValue.
-
-
Stop the cluster and clean data:
docker-compose down -v
To run unit tests:
go test ./...To run integration tests (Docker required):
go test -tags=integration ./test/integration