Implemtation of Raft consensus algorithm in JavaScript.
- Environment: Open the project in n terminal windows, where n is the number of nodes in the system.
- Execution: In each of n terminal windows, run
node index.js [n] [m]where n is the total nodes and m is the current node id. - Communication: Upon reaching consensus, the system is ready for interaction via RESTful endpoints:
- Execute:
localhost:300[m]/where m is the id of the leader, used to give new command to execute and store. - Retrieve:
localhost:300[m]/logwhere m can be any node, used to retrieve the current state of the system.
- Open project in terminal, set node.js 21 environment (if needed,
nvm use 21for Node Version Manager) - run
./raft_demo.sh 3to launch 3 nodes. Find out the id of current leader from launched terminal windows. - Use Postman or any API testing tool to issue commands and retrive state.
- You may simulate a node failure by using the
localhost:300[m]/killendpoint to kill the node with id = m.
Consensus algorithms are protocols used in distributed systems to achieve agreement on a single data value among distributed processes or systems. This is crucial for ensuring consistency and reliability in environments where multiple nodes or machines must work together.
- Nodes: Independent processes or machines that participate in the consensus.
- Proposals: Values that nodes suggest to be agreed upon.
- Quorum: The minimum number of nodes that must agree for the decision to be valid.
- Fault Tolerance: The ability of the system to continue functioning correctly even when some nodes fail or act maliciously.
- Propose: Nodes propose values to be agreed upon.
- Vote: Nodes vote on the proposed values.
- Decision: Once a quorum is reached, the decision is made.
- Broadcast: The agreed-upon value is broadcast to all nodes.
- Consistency: All nodes agree on the same value.
- Availability: The system can continue to operate even if some nodes fail.
- Partition Tolerance: The system can handle network partitions where some nodes cannot communicate.
- Blockchain: Ensures all nodes in the network agree on the state of the ledger.
- Distributed Databases: Ensures data consistency across different nodes.
- Fault-Tolerant Systems: Provides reliability and availability in critical systems.