This educational project demonstrates a distributed key-value store using raw TCP connections with Node.js and TypeScript. It is designed to help you understand the principles of distributed systems, low-level networking, and CLI-based interaction.
- Distributed Architecture: Operates across three nodes to ensure data consistency.
- Command Support: Implements basic commands like
GET
,SET
,UPD
, andDEL
. - Node Failure Detection: Monitors and manages node failures with a heartbeat mechanism.
- Recovery Mechanism: Synchronizes recovered nodes with the rest of the system.
- CLI Tools: Provides command-line interfaces for both server management and client interactions.
-
Clone the Repository
git clone https://github.com/your-username/distributed-key-value.git cd distributed-key-value
-
Install Dependencies
npm install
To start a server, use the following command:
npm start
You will be prompted to choose which server instance to run.
To interact with a server, use the following command:
npm test
You will be prompted to select a server instance and then execute commands like SET
, GET
, UPD
, and DEL
.
Diagram showing the overall architecture of the distributed key-value store system.
Diagram illustrating how the SET
command is forwarded from Server A to other nodes.
Starting a Server
Screen recording of the CLI prompt for selecting and starting a server.
Sending Commands
Screen recording of the CLI interaction for sending commands to a server.
-
Start Server Instances:
Run the servers usingnpm start
for Server A, Server B, and Server C. -
Set a Value Using Client CLI:
Connect to Server A and execute the command:SET myKey myValue
The
SET
command will be forwarded to Server B and Server C. -
Get the Value:
Execute the command to retrieve the value:GET myKey
Confirm that
myKey
returnsmyValue
from Server A, Server B, and Server C. -
Update the Value:
Update the value using the command:UPD myKey newValue
Ensure that all servers reflect the updated value
newValue
. -
Delete the Key:
Execute the delete command:DEL myKey
Verify that
myKey
is no longer present on Server A, Server B, and Server C.
-
Start Server Instances:
Ensure all server instances are running. -
Simulate Node Failure:
Stop Server B to simulate a failure. -
Send Commands:
Execute commands using the Client CLI and verify that Server A and Server C process them. -
Restart the Failed Node:
Restart Server B and check the recovery process. -
Verify Recovery:
Confirm that Server B resynchronizes with Server A and Server C and reflects the latest data. -
Check Data Consistency:
Ensure that all servers have consistent data after the recovery of Server B.