A distributed, fault-tolerant key-value store implemented using a controller–worker architecture. The system supports key-space partitioning, three-way replication, quorum-based writes, REST APIs for client interaction, and automatic recovery from worker failures. It is fully containerized using Docker and deployable on Kubernetes.
- Overview
- System Architecture
- Key Features
- API Endpoints
- Replication Model
- Failure Handling
- Deployment
- Project Structure
- Technologies Used
- Future Improvements
- License
This project implements a distributed key-value store designed to achieve high availability, scalability, and fault tolerance. The system consists of:
- A single controller node
- Four worker nodes
- Replication across three workers per key
- REST API for GET and PUT operations
- gRPC-based internal communication between nodes
The system ensures strong consistency through quorum-based writes and maintains availability through periodic worker heartbeats and automated re-replication.
The architecture is divided into:
- Controller (Control Plane) – manages metadata, partitions keys, assigns replicas, and monitors workers.
- Workers (Data Plane) – store key-value data, handle REST operations, and manage replication.
- Supporting Services – MongoDB for storage, Redis and etcd for coordination, and Kubernetes for orchestration.
- Clients query the controller to locate the appropriate worker.
- Clients perform GET/PUT on the designated worker.
- Replication is performed synchronously (1 extra replica) and asynchronously (1 replica).
- Key-space partitioning across 4 workers
- Three-way replication for all keys
- Quorum-based write acknowledgment
- Automatic detection of worker failure
- Automated re-replication to maintain replica count
- Deployment support via Docker Compose for local testing and minikube to test for cloud deployment.
- REST API (client) + gRPC (internal)
Returns the primary worker and replica nodes for a given key.
GET /mapping?key=<key>Response:
{
"primary": "worker2",
"replicas": ["worker3", "worker4"]
}Returns a list of workers and their health status.
GET /nodesUsed by workers to signal availability.
POST /heartbeatUsed by workers to rebalance in case of worker failure.
POST /rebalanceRetrieves the value for a specific key.
GET /kv/<key>Accepts a JSON payload to store and triggers replication.
PUT /kv/<key>Body:
{
"value": "123",
"version": 1
}- Redundancy: Each key is stored on three workers.
- PUT Operation (Quorum):
- Primary worker receives request.
- Worker performs synchronous replication to one replica.
- Worker performs asynchronous replication to the third replica.
- Operation is successful after two replicas acknowledge (Primary + 1 Sync).
- GET Operation:
- Always served by the primary worker for low latency.
- Workers send periodic heartbeats to the controller.
- Detection: If controller doesn't detect heartbeat for 10s, the worker is marked as failed.
- Recovery: The controller reassigns key partitions and triggers automated re-replication to restore the 3-replica count.
- This ensures fault tolerance and continuous availability even if a node goes down.
To run the entire system locally for development:
docker-compose up --buildTo deploy the system on a Kubernetes cluster:
kubectl apply -f k8s/namespace.yml
kubectl apply -f k8s/etcd/
kubectl apply -f k8s/redis/
kubectl apply -f k8s/mongo/
kubectl apply -f k8s/controller/
kubectl apply -f k8s/workers/Cloud-Distributed-DB-main/
│
├── controller/ # Controller logic and API
├── worker/ # Worker node logic and storage
├── operator/ # Kubernetes operator for automation
├── k8s/ # Kubernetes manifests
│ ├── controller/
│ ├── workers/
│ ├── mongo/
│ ├── redis/
│ ├── etcd/
│ └── namespace.yml
├── proto/ # gRPC protobuf definitions
├── scripts/ # Helper scripts
├── docker-compose.yml # Local deployment config
└── README.md
- Python: Core implementation language
- FastAPI: REST API interface
- gRPC: Efficient internal node communication
- MongoDB: Persistent data storage
- Redis: Metadata buffer and state management
- etcd: Distributed cluster coordination
- Docker: Containerization
- Kubernetes: Orchestration and scaling
- Consistent hashing for dynamic scaling
- Horizontal auto-scaling of worker pods
- Multi-region replication
- Load balancing for high-throughput workloads
- Comprehensive monitoring using Prometheus and Grafana
This project is released under the MIT License.