Skip to content

ali-master/raft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

53 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

RAFT Logo

RAFT

Production-ready Raft consensus implementation for Node.js

npm version license downloads stars

Quick Start โ€ข Documentation โ€ข Examples โ€ข Why RAFT?


โš ๏ธ Note: This library is under active development and therefore full backward compatibility is not guaranteed before reaching v1.0.0. Star the repo to get notified!

๐ŸŽฏ What is RAFT?

RAFT is a battle-tested implementation of the Raft consensus algorithm for Node.js, designed to help you build bulletproof distributed systems. Whether you're building a distributed database, configuration service, or any system requiring strong consistency across multiple nodes, RAFT has you covered.

โœจ Key Features

๐Ÿ—๏ธ Core Capabilities

  • ๐Ÿ”„ Consensus Algorithm - Implements the Raft consensus algorithm for distributed systems
  • ๐ŸŽฏ Complete Raft Implementation - Leader election, log replication, and membership changes
  • ๐Ÿ›ก๏ธ Production-Ready - Built for reliability, performance, and observability
  • ๐Ÿ’พ Redis-Backed Storage - Persistent state management and peer discovery
  • ๐ŸŽฒ Weighted Voting - Advanced leader election with configurable weights
  • ๐Ÿ”„ Dynamic Membership - Add or remove nodes without downtime

๐Ÿ”ง Reliability & Performance

  • โšก High Availability - Automatic failover and leader election
  • ๐Ÿ”„ Log Replication - Efficient log replication with strong consistency
  • ๐Ÿ”„ Membership Changes - Dynamic cluster membership management
  • ๐Ÿ”„ Snapshotting - Periodic snapshots for efficient state management
  • ๐Ÿ”„ Append-Only Log - Durable, append-only log for all operations
  • ๐Ÿ”Œ Circuit Breakers - Fault tolerance for network operations
  • ๐Ÿ“Š Comprehensive Monitoring - Prometheus metrics and detailed logging
  • ๐Ÿ“ Write-Ahead Logging - Durable log storage with automatic recovery
  • ๐Ÿ” Peer Discovery - Automatic peer discovery and health checking
  • ๐Ÿ“ˆ High Throughput - Optimized for low-latency operations and high throughput
  • ๐Ÿ”„ Automatic Failover - Seamless leader election and failover handling
  • ๐Ÿ›ก๏ธ Split-Brain Prevention - Mechanisms to prevent data inconsistency during network partitions
  • ๐Ÿ”’ Security Features - TLS support, authentication, and access control
  • ๐Ÿ“ฆ Modular Design - Easily extendable with custom plugins and middleware
  • ๐Ÿ”„ Event-Driven - Rich event system for state monitoring and custom actions
  • ๐Ÿ“ฆ TypeScript Support - Full type safety and IntelliSense for a better developer experience
  • ๐Ÿ”— Easy Integration - Simple API for Node.js and NestJS applications
  • ๐Ÿ“š Extensive Documentation - Comprehensive guides, examples, and API references
  • ๐ŸŒ Cross-Platform - Works seamlessly on Linux, macOS, and Windows
  • ๐Ÿ”„ Multi-Node Clusters - Supports clusters of any size with automatic scaling
  • ๐Ÿ”„ Real-Time Updates - Push updates to clients in real-time using WebSockets or HTTP/2
  • ๐Ÿ”„ Customizable - Easily configure timeouts, retry policies, and other parameters

๐Ÿš€ Developer Experience

  • ๐Ÿ“ก Event-Driven Architecture - Rich event system for state monitoring
  • ๐Ÿ“˜ TypeScript First - Full type safety and IntelliSense support
  • ๐Ÿ”ง Easy Integration - Simple API for Node.js and NestJS
  • ๐Ÿ“š Extensive Documentation - Comprehensive guides and examples

๐Ÿšฆ Quick Start

Installation

# npm
npm install @usex/raft

# yarn
yarn add @usex/raft

# pnpm
pnpm add @usex/raft

Basic Usage

import { RaftEngine } from '@usex/raft';

// 1. Initialize the engine
const engine = new RaftEngine();

// 2. Create a node
const config = RaftEngine.createDefaultConfiguration('node1', 'my-cluster');
const node = await engine.createNode(config);

// 3. Start the node
await engine.startNode('node1');

// 4. Listen for events
node.on('stateChange', ({ state, term }) => {
  console.log(`Node is now ${state} for term ${term}`);
});

// 5. Write data (if leader)
if (node.isLeader()) {
  await node.appendLog({
    command: 'SET',
    key: 'user:123',
    value: { name: 'Alice', role: 'admin' }
  });
}

๐Ÿ’ก Why RAFT?

๐ŸŽฏ Perfect For

  • Distributed Databases - Build consistent, replicated data stores
  • Configuration Services - Manage distributed configuration with strong consistency
  • Service Discovery - Implement reliable service registries
  • Distributed Locks - Create distributed locking mechanisms
  • Leader Election - Coordinate distributed services
  • State Machines - Implement replicated state machines
  • Event Sourcing - Build event-driven architectures with strong consistency
  • Microservices - Ensure reliable communication and state management across services
  • Real-Time Applications - Maintain consistent state in real-time systems
  • IoT Systems - Manage distributed IoT devices with strong consistency
  • Gaming Servers - Implement leaderboards and game state management
  • Blockchain Applications - Build consensus mechanisms for blockchain networks
  • Financial Systems - Ensure transaction consistency in distributed financial applications
  • Data Replication - Replicate data across multiple nodes for high availability
  • Analytics Platforms - Maintain consistent state in distributed analytics systems
  • Content Delivery Networks (CDNs) - Ensure consistent content across distributed nodes
  • Search Engines - Implement distributed search with strong consistency
  • Machine Learning Systems - Manage distributed model training and inference
  • Cloud Services - Build reliable cloud-native applications with strong consistency
  • Edge Computing - Ensure consistent state across edge devices
  • API Gateways - Implement consistent routing and state management
  • Message Brokers - Build reliable message delivery systems
  • Data Warehousing - Ensure consistent data across distributed data warehouses
  • Backup and Recovery - Implement reliable backup and recovery mechanisms

๐Ÿ›ก๏ธ Battle-Tested Features

  • Automatic Failover - Seamless leader election when nodes fail
  • Split-Brain Prevention - Built-in mechanisms to prevent data inconsistency
  • Network Partition Handling - Graceful handling of network splits
  • Data Consistency - Strong consistency guarantees across all nodes

๐Ÿ“– Documentation

๐Ÿƒ Getting Started

๐Ÿ“š Core Concepts

๐Ÿ”ฌ Advanced Topics

๐Ÿ› ๏ธ Troubleshooting

๐Ÿ’ป System Requirements

  • Node.js >= 18.12.0
  • Redis >= 6.0
  • TypeScript >= 5.0 (for TypeScript projects)

๐ŸŽฎ Interactive Example

Want to see RAFT in action? Check out our interactive examples:

Three-Node Cluster Example

// Node 1 - Initial Leader
const node1 = await createNode('node1', { weight: 3 });

// Node 2 & 3 - Followers
const node2 = await createNode('node2', { weight: 2 });
const node3 = await createNode('node3', { weight: 1 });

// Simulate leader failure
await node1.stop();
// Node 2 becomes leader due to higher weight!

See More Examples โ†’

๐Ÿค Contributing

We love contributions! Whether it's:

  • ๐Ÿ› Bug fixes
  • โœจ New features
  • ๐Ÿ“š Documentation improvements
  • ๐Ÿ’ก Ideas and suggestions

Check out our Contributing Guide to get started.

๐Ÿ“Š Performance

RAFT is designed for high performance:

  • < 50ms leader election in typical scenarios
  • 10,000+ ops/sec throughput on commodity hardware
  • Minimal memory footprint with efficient state management

๐Ÿ›ก๏ธ Security

  • TLS Support - Encrypted communication between nodes
  • Authentication - Built-in node authentication
  • Access Control - Fine-grained permissions for operations

Learn more about security โ†’

๐Ÿ“ฑ Community & Support

๐Ÿ“œ License

This project is licensed under the MIT License. See the LICENCE file for details.


Ready to build distributed systems that just work?

๐Ÿš€ Get Started โ€ข ๐Ÿ“š View Examples โ€ข โญ Star on GitHub

Made with โค๏ธ by Ali Master and the open source community.

About

Raft consensus for Node.js. Build distributed systems with leader election, fault tolerance, and data replication.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages