ring-election
v1.1.0
Published
Leader and followers algorithm to make partitioning easy.
Downloads
80
Maintainers
Readme
Ring election
Is your dream to build a service like cassandra,kafka,zipkin,jaeger,redis,etc...? You are in the right place , join ring-election project !!!
docker-compose up
Check assigned partitions to local:9000/status or change the port to 9001/9002 Try to stop and restart container and observe the behaviour. If you want to develop new features or fix a bug you can do that without docker images , just configure environment variables correctly ( you can see them on [docker-compose.yaml] file) . See Examples section to know how to integrate this library and build some distributed services on top of ring-election !!!
What the ring-election driver offers you ?
- A default partitioner that for an object returns the partition to which it is assigned.
- Mechanism of leader election
- Failure detection between nodes.
- Assignment and rebalancing of partitions between nodes
- Automatic re-election of the leader
What problems can you solve with this driver ?
- Scalability
- High availability
- Concurrency between nodes in a cluster
- Automatic failover
This section introduce you on what you can build on top of ring-election using it as driver/library.
Distributed Scheduler Each Scheduler instance will work on the assigned partitions . A real implementation of this use case is available here https://github.com/pioardi/hurricane-scheduler
Distributed lock Distributed cache Distributed computing
const ring = require('ring-election');
let leader = ring.leader;
leader.createServer();
// if you want REST API as monitoring , invoke startMonitoring
leader.startMonitoring();
// to get ring info
ring.leader.ring();
// Your leader will be the coordinator.
How to follower
const ring = require('ring-election')
let follower = ring.follower
const {
BECOME_LEADER,
PARTITIONS_ASSIGNED,
PARTITIONS_REVOKED
} = ring.constants;
follower.createClient()
// if you want REST API as monitoring , invoke startMonitoring
follower.startMonitoring()
// to get ring info
ring.follower.ring()
// to get assigned partitions
let assignedPartitions = ring.follower.partitions()
// now let me assume that a follower will create some data
// and you want to partition this data
let partition = ring.follower.defaultPartitioner('KEY')
// save your data including the partition on a storage
// you will be the only one in the cluster working on the partitions assigned to you.
// If you want to handle partitions assigned ( use other constants to listen other events ) you can do in this way.
ring.follower.eventListener.on(PARTITIONS_ASSIGNED , (newAssignedPartitions) => {
// DO STUFF
})
Try it out !
docker image build -t ring-election .
docker-compose up
See examples folder for more advanced examples
Re-add a client in the cluster when it was removed and send an hearth beat Implement event emitter to notify library users when something happens