👀 High-performance distributed key-value store in C++
This project implements a distributed key-value store in C++ using TCP sockets and multithreading, mimicking a simplified Redis. Multiple nodes communicate to store, replicate, and retrieve key-value pairs.
Supports:
SET <key> <value>→ Save a key-value pairGET <key>→ Retrieve value from key- Replication across nodes
- Basic error handling and multithreaded client support
Single server storage is risky due to failures. Distributing and replicating data across nodes enhances fault tolerance, scalability, and resilience. This project introduces concepts like TCP socket programming, multithreading, and replication in C++.
.
├── main.cpp # Entry point
├── server.cpp/.h # TCP server & request handling
├── storage.cpp/.h # In-memory key-value storage
├── replica.cpp/.h # Replication logic
├── test.sh # Automated test script
├── README.md # This file
Requires a C++11+ compiler with pthreads.
g++ main.cpp server.cpp storage.cpp replica.cpp -o kv_store -pthread -std=c++17In terminal 1:
./kv_store 9000In terminal 2:
./kv_store 9001Use netcat (nc) to send commands:
nc localhost 9000
SET name john
OK
GET name
johnchmod +x test.sh
./test.shTests include:
- Basic set/get
- Replication between nodes
- Stress test with multiple keys
- Edge cases (missing keys)
- Replication is asynchronous, no retry on failure.
- Only supports two nodes (easy to expand).
- No persistence to disk.
- No conflict resolution for concurrent key sets.
- Add master node for coordination
- Implement consistency models (eventual, strong, quorum)
- Add hashing/sharding
- Add persistence (file or SQLite)
- Add CLI client