A Redis-like distributed key-value store implemented in Java with clustering capabilities.
This project provides a lightweight distributed in-memory database, interfaced with a CLI. Supports a distributed architecture with a coordinator node and multiple storage nodes using modulo-based sharding strategy, enabling horizontal scalability. The system ensures data durability through periodic disc persistence and offers basic fault tolerance with node failure recovery via WAL.
Failure of any node is managed by the coordinator node, by delegating failed node's work to another healthy node and, once the failed node is back online, it syncs the state via 2 WAL's:
- Primary WAL: Logs from the failed storage node
- Secondary WAL: Logs from the coordinator node that were kept while the node was down
- The server uses a combination of TCP sockets and gRPC for server-server communication
- Individual nodes can be accessed directly or through the coordinator
KvDB follows a distributed architecture with the following components:
- Coordinator Node: Manages the cluster topology, routes client requests to appropriate nodes. Performs health checks and delegates tasks in case of node failures.
- Storage Nodes: Store the actual key-value data and handle read/write operations
- Client Interface: Connects to the coordinator for executing commands
+-----------------------------+
| Client / CLI |
+-------------+---------------+
|
v
+-------------+---------------+
| Coordinator Node |
| - Knows cluster topology |
| - Handles client requests |
| - Routes to correct node |
+-------------+---------------+
|
----------------+------------------
| | |
+-----+-----+ +-----+-----+ +------+------+
| Node A | | Node B | | Node C |
| - KV store| | - KV store| | - KV store |
+-----------+ +-----------+ +-------------+
- Java 11 or higher
- Maven
- Package the project using Maven:
make java- Start the Cluster: Coordinator Server and Node Servers
make run_cluster - Start the Client CLI
Option 1 (recommended): Use kvcli CLI Go application
make build_cli
# connect to the cluster
kv connect --host localhost --port 7000KV SET key value- Set key to hold string valueKV GET key- Get the value of keyKV DEL key- Delete one or more keys
PING- Test connectionHELP- Show help messageEXIT- Exit the client
Storage node configuration is done via application.properties file located in the kv.common/src/main/resources/<node_id> directory for locally running.
If running the storage nodes remotely, the configuration files should be placed in kv.server/src/main/resources/<node_id> directory.
The system supports file-based persistence with options for auto-flushing and custom file types.
kvdb.persistence.filepath=data/kvstore.dat
kvdb.persistence.filetype=dat
kvdb.persistence.enableAutoFlush=true
kvdb.persistence.autoFlushInterval=2The coordinator uses a YAML configuration file to define the cluster topology, located in the kv.coordinator/src/main/resources/cluster-config.yaml file:
nodes:
- id: node1
host: 127.0.0.1
port: 8081
useGrpc: true
- id: node2
host: 127.0.0.1
port: 8082
useGrpc: true
This project is licensed under the MIT License.
