A distributed key-value store built with Go and gRPC, featuring Raft consensus for high availability and consistency.
- Distributed Architecture: Multi-node cluster with automatic leader election
- Raft Consensus: Strong consistency guarantees through Raft protocol
- gRPC API: High-performance RPC communication
- CRUD Operations: Get, Set, Delete, and List operations
- Cluster Management: Join/leave cluster operations
- Health Monitoring: Built-in health checks
- TTL Support: Time-to-live for key expiration
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Node 1 │ │ Node 2 │ │ Node 3 │
│ (Leader) │◄──►│ (Follower) │◄──►│ (Follower) │
│ │ │ │ │ │
│ ┌─────────────┐ │ │ ┌─────────────┐ │ │ ┌─────────────┐ │
│ │ gRPC API │ │ │ │ gRPC API │ │ │ │ gRPC API │ │
│ └─────────────┘ │ │ └─────────────┘ │ │ └─────────────┘ │
│ ┌─────────────┐ │ │ ┌─────────────┐ │ │ ┌─────────────┐ │
│ │ Raft Engine │ │ │ │ Raft Engine │ │ │ │ Raft Engine │ │
│ └─────────────┘ │ │ └─────────────┘ │ │ └─────────────┘ │
│ ┌─────────────┐ │ │ ┌─────────────┐ │ │ ┌─────────────┐ │
│ │ Storage │ │ │ │ Storage │ │ │ │ Storage │ │
│ └─────────────┘ │ │ └─────────────┘ │ │ └─────────────┘ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
- Go 1.21 or later
- Protocol Buffers compiler (protoc)
- Clone the repository:
git clone <repository-url>
cd distributed-kv-store- Install dependencies and generate code:
make setup- Start the first node (will become leader):
./kv-server --node-id=node1 --address=localhost:8080 --data-dir=./data/node1- Start additional nodes:
./kv-server --node-id=node2 --address=localhost:8081 --data-dir=./data/node2 --join=localhost:8080
./kv-server --node-id=node3 --address=localhost:8082 --data-dir=./data/node3 --join=localhost:8080- Use the client to interact with the cluster:
./kv-client --server=localhost:8080 set key1 value1
./kv-client --server=localhost:8080 get key1
./kv-client --server=localhost:8080 list-keysGet(key)- Retrieve a value by keySet(key, value, ttl)- Store a key-value pair with optional TTLDelete(key)- Remove a key-value pairListKeys(prefix, limit)- List keys with optional prefix filterJoinCluster(node_id, address)- Add a new node to the clusterLeaveCluster(node_id)- Remove a node from the clusterGetClusterInfo()- Get information about cluster nodesHealthCheck()- Check node health status
The server can be configured via command-line flags or environment variables:
--node-id: Unique identifier for this node--address: Address to bind the gRPC server--data-dir: Directory for Raft logs and storage--join: Address of an existing node to join--log-level: Logging level (debug, info, warn, error)
make build # Build all binaries
make server # Build server only
make client # Build client only
make test # Run tests
make clean # Clean build artifacts