All Projects → pioardi → ring-election

pioardi / ring-election

Licence: MIT License
A node js library with a distributed leader/follower algorithm ready to be used

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to ring-election

Kafka Monitor
Xinfra Monitor monitors the availability of Kafka clusters by producing synthetic workloads using end-to-end pipelines to obtain derived vital statistics - E2E latency, service produce/consume availability, offsets commit availability & latency, message loss rate and more.
Stars: ✭ 1,817 (+1875%)
Mutual labels:  cluster, leader, partition
Thespian
Python Actor concurrency library
Stars: ✭ 220 (+139.13%)
Mutual labels:  distributed-systems, scalability, concurrency
Cloudi
A Cloud at the lowest level!
Stars: ✭ 352 (+282.61%)
Mutual labels:  distributed-systems, scalability, concurrency
Atomix
A reactive Java framework for building fault-tolerant distributed systems
Stars: ✭ 2,182 (+2271.74%)
Mutual labels:  distributed-systems, distributed-lock, leader-election
Orleans
Orleans is a cross-platform framework for building distributed applications with .NET
Stars: ✭ 8,131 (+8738.04%)
Mutual labels:  distributed-systems, scalability, concurrency
Zio Saga
Purely Functional Transaction Management In Scala With ZIO
Stars: ✭ 200 (+117.39%)
Mutual labels:  distributed-systems, concurrency
concurrent-ll
concurrent linked list implementation
Stars: ✭ 66 (-28.26%)
Mutual labels:  scalability, concurrency
beems
a bee-queue based minimalist toolkit for building fast, decentralized, scalable and fault tolerant microservices
Stars: ✭ 33 (-64.13%)
Mutual labels:  scalability, concurrency
jakob
A fault-tolerant, distributed cluster of Redis servers with built-in load-balancing and fall-backs to provide data availability
Stars: ✭ 19 (-79.35%)
Mutual labels:  distributed-systems, cluster
Akka
Build highly concurrent, distributed, and resilient message-driven applications on the JVM
Stars: ✭ 11,938 (+12876.09%)
Mutual labels:  distributed-systems, concurrency
raftor
Distributed chat system built with rust
Stars: ✭ 31 (-66.3%)
Mutual labels:  distributed-systems, cluster
distributed-dev-learning
汇总、整理常用的分布式开发技术,给出demo,方便学习。包括数据分片、共识算法、一致性hash、分布式事务、非侵入的分布式链路追踪实现原理等内容。
Stars: ✭ 39 (-57.61%)
Mutual labels:  distributed-systems, distributed-lock
Bastion
Highly-available Distributed Fault-tolerant Runtime
Stars: ✭ 2,333 (+2435.87%)
Mutual labels:  distributed-systems, concurrency
nebula
A distributed, fast open-source graph database featuring horizontal scalability and high availability
Stars: ✭ 8,196 (+8808.7%)
Mutual labels:  distributed-systems, scalability
Systemizer
A system design tool that allows you to simulate data flow of distributed systems.
Stars: ✭ 1,219 (+1225%)
Mutual labels:  distributed-systems, scalability
skyring
Distributed timers as a service - for Node.js
Stars: ✭ 27 (-70.65%)
Mutual labels:  distributed-systems, cluster
traffic
Massively real-time traffic streaming application
Stars: ✭ 25 (-72.83%)
Mutual labels:  distributed-systems, concurrency
transit
Massively real-time city transit streaming application
Stars: ✭ 20 (-78.26%)
Mutual labels:  distributed-systems, concurrency
Gauntlet
🔖 Guides, Articles, Podcasts, Videos and Notes to Build Reliable Large-Scale Distributed Systems.
Stars: ✭ 336 (+265.22%)
Mutual labels:  distributed-systems, scalability
Vertx In Action
Examples for the Manning "Vert.x in Action" book
Stars: ✭ 134 (+45.65%)
Mutual labels:  distributed-systems, scalability

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 !!!

Coverage Status Actions Status Actions Status Codacy Badge npm version Gitter chat
JavaScript Style Guide

Contents

Getting started · Overview · Use cases · Config · Config · Monitoring · High level design · Contribute · Versioning · License

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
  • Listen for new assigned/revoked partitions

What problems can you solve with this driver ?

  • Scalability
  • High availability
  • Concurrency between nodes in a cluster
  • Automatic failover

Getting started

Install with npm !
  npm i ring-election --save

Example You do not need to choose a node as leader , just indicate all your nodes and start everyone as follower.
The first node to start will be the leader , the leader do not have assigned partitions so try to start 2 instances after your integration

How to integrate

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
})

Start your development cluster

You will find some helpful files into the dev folder , please see the following video

Watch the video

Check assigned partitions to local:9000/status or change the port to 9001/9002

Try to stop and restart processes and observe the behaviour.

Overview and rationale

In modern systems it is often needed to distribute the application load to make the system scalable so that every data is processed by a single instance.
Ring-election is a driver that implements a distributed algorithm that assigns to each node the partitions to work on . In a simple use case each node can obtain data that are part of the partitions of which it is owner and work on them.
The algorithm will assign to each node one or more partitions to work with.
A node will be removed if it does not send an heart beat for a while , this process is called heart check.
Each node in the ring will have an ID and a priority , if the leader node will die the node with lower priority will be elect as leader.
If a node is added or removed from the cluster, the allocated partitions will be rebalanced.

Use cases

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
Dynamic diagram

Distributed lock
Distributed cache
Distributed computing

Try it out !

   docker image build -t ring-election .
   docker-compose up

Configuration

PORT : The leader will start to listen on this port , default is 3000
TIME_TO_RECONNECT: The time to wait for a follower when he has to connect to a new leader in ms , default is 3000ms
HEART_BEAT_FREQUENCY: The frequency with which a heart beat is performed by a follower , default is 1000ms
HEART_BEAT_CHECK_FREQUENCY: The frequency with which an heart check is performed by a leader , default is 3000ms
LOG_LEVEL: Follow this https://www.npmjs.com/package/winston#logging-levels , default is info.
NUM_PARTITIONS: Number of partitions to distribute across the cluster , default is 10.
SEED_NODES : hostnames and ports of leader node comma separated, Ex . hostname1:port,hostname2:port
MONITORING_PORT : port to expose rest service for monitoring , default is 9000

Monitoring API

To monitor your cluster contact any node on the path /status (HTTP verb : GET) or contact a follower node on /partitions (HTTP verb : GET).

High Level Diagram

See wiki page.

How to contribute

See contributing guidelines CONTRIBUTING

Versioning

We use (http://semver.org/) for versioning.

License

This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].