https://github.com/maxenglander/raftjs
Educational implementation of Raft protocol in TypeScript
https://github.com/maxenglander/raftjs
Last synced: about 1 year ago
JSON representation
Educational implementation of Raft protocol in TypeScript
- Host: GitHub
- URL: https://github.com/maxenglander/raftjs
- Owner: maxenglander
- Created: 2019-04-14T20:37:23.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T04:08:29.000Z (over 3 years ago)
- Last Synced: 2025-04-11T01:53:04.149Z (about 1 year ago)
- Language: TypeScript
- Size: 966 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# raftjs
This is a (partial) implementation of the [Raft](https://raft.github.io/raft.pdf)
protocol in JavaScript (by way of TypeScript). The purpose of this
implementation is to educate the author, and any interested readers,
in what an implementation might look like.
The implementation aims to be understandable, well-organized and extensible.
It attempts to follow the Raft protocol to the letter. However, there
are likely places where the language is misinterpreted or followed too
literally. There are likely to be many bugs and mistakes in this
implementation.
At the present time, the implementation includes only leader election,
The implementation does not presently include:
* the leader accepting new entries from clients
* the leader replicating log entries to followers
* changes in cluster membership
* snapshotting or log compaction
## Build
```
$> npm install
$> npm run build
```
## Docs
View the [annotated source](https://raftjs.maxenglander.com/annotated-source.html).
## Example usage
**Start Raftjs servers**
```
$> ./bin/rafjs start --config-file examples/configuration/server-a.json > /tmp/raftjs-server-a.log
$> RAFTJS_SERVER_A_PID=$!
$> ./bin/rafjs start --config-file examples/configuration/server-b.json > /tmp/raftjs-server-b.log
$> RAFTJS_SERVER_B_PID=$!
$> ./bin/rafjs start --config-file examples/configuration/server-c.json > /tmp/raftjs-server-c.log
$> RAFTJS_SERVER_C_PID=$!
```
**Check current leader**
```
$> grep leader /tmp/raftjs-server\*.log
/tmp/raftjs-server-a.log:[1555273638878] DEBUG (84785 on local): Votes obtained from cluster majority; transitioning to leader
```
**Kill the initial leader**
```
$> kill $RAFTJS_SERVER_A_PID
```
**Check the new leader**
```
$> grep leader /tmp/raftjs-server-\*log
/tmp/raftjs-server-a.log:[1555273638878] DEBUG (84785 on local): Votes obtained from cluster majority; transitioning to leader
/tmp/raftjs-server-b.log:[1555273762740] DEBUG (84787 on local): Votes obtained from cluster majority; transitioning to leader
```