npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ndk-rpc-cluster

v2.0.0

Published

Enterprise-grade RPC cluster system with load balancing, fault tolerance, service discovery and automatic failover support

Readme

NDK-RPC-Cluster

npm version License: MIT Node.js Version

Enterprise-grade RPC cluster system with load balancing, fault tolerance, service discovery and automatic failover support

🚀 Features

  • 🔄 Auto Replica Creation - Automatic Replica Creation if in 10 seconds more than threshold requests are received with respect to number of replicas
  • ⚡ Custom Threshold - Configure request threshold for auto-scaling (default: 2000)
  • 🌐 Protocol Support - Support for both HTTP and HTTPS protocols
  • 🔌 Port Configuration - Flexible port management with portRequired option
  • 🔄 Load Balancing - Round-robin distribution across replicas
  • ⚡ Fault Tolerance - Automatic retry mechanisms and failover
  • 🔍 Service Discovery - Global registry for service management
  • 📡 RPC Support - Remote procedure calls with full cluster support
  • 🛡️ Error Handling - Comprehensive error management
  • 🔧 Easy Setup - Simple configuration and deployment

📦 Installation

npm install ndk-rpc-cluster
# or
yarn add ndk-rpc-cluster
# or
pnpm add ndk-rpc-cluster

🔄 Recent Updates

  • Added support for custom protocols (HTTP/HTTPS)
  • Added portRequired option for flexible URL generation
  • Improved error handling and logging
  • Enhanced configuration options for better control

🏗️ Architecture

NDK-RPC-Cluster Architecture

🚀 Quick Start

1. Create Load Balancer with Replicas

Load Balancer 1

import ndk_load_balancer from "ndk-rpc-cluster/loadBalancer";

let registerFns = [
  {
    function_name: "add",
    function_block: ({ a, b }) => a + b,
  },
];

let config = {
  replicas: 3, // replicas want to create
  port: 3000, // port of load balancer
  register_functions: registerFns, // function to register on replicas
  threashold: 30000 // it means if req reach 30,000 then creates new replica
};

const lb = new ndk_load_balancer(config);
await lb.start(); // start the load balancer server

Load Balancer 2

import ndk_load_balancer from "ndk-rpc-cluster/loadBalancer";

let registerFns = [
  {
    function_name: "sub",
    function_block: ({ a, b }) => a - b,
  },
];

let config = {
  replicas: 3, // replicas want to create
  port: 4000, // port of load balancer
  register_functions: registerFns, // function to register on replicas
  threashold: 50000, // it means if req reach 50,000 then creates new replica
};

const lb = new ndk_load_balancer(config);
await lb.start(); // start the load balancer server

2. Setup Global Registry

import GlobalRegister from "ndk-rpc-cluster/registry";

const global = new GlobalRegister({
  createMiddleware: true, // it must true , it will create middle server
});

let keys = {
  AddService: {
    host: "localhost", // load balancer host
    port: 3000, // load balancer port
    protocol: "http", // http or https
    portRequired: true // include port in service URL (default: true)
  },
  SubService: {
    host: "localhost", // load balancer host
    port: 4000, // load balancer port
    protocol: "http", // http or https
    portRequired: false // service will be accessed without port in URL
  },
};

global.registerKeys(keys);
await global.start(); // start the global registry + middle server
// Registry runs on port 3331, Middleware on port 4132

3. Create Client

import { Client } from "ndk-rpc-cluster/client";

const client = new Client();

const response = await client.request({
  method: "add", // method name to run
  params: {
    // parameters to pass else {}
    a: 2,
    b: 3,
  },
  key: "AddService", // key of service that we declare in Global Registry
});

console.log("Res: ", response);

🛠️ Configuration

Load Balancer Options

| Option | Type | Default | Description | | -------------------- | ------ | ------- | --------------------------------- | | port | number | - | Load balancer server port | | replicas | number | - | Number of replica servers | | basePort | number | - | Starting port for replicas | | protocol | string | "http" | Protocol to use (http/https) | | portRequired | boolean| true | Whether to include port in URLs | | register_functions | array | - | Functions to register on replicas |

Registry Options

| Option | Type | Default | Description | | ------------------ | ------- | ------- | ----------------------------- | | createMiddleware | boolean | true | Auto-create middleware server |

🔧 Scripts

# Start complete cluster
npm run cluster:start

# Start individual components
npm run start:registry
npm run start:load-balancer
npm run start:middleware

# Run tests
npm test
npm run test:client
npm run test:server

# Development mode
npm run dev

🌐 Default Ports

  • Global Registry: 3331
  • Middleware Server: 4132
  • Load Balancer: 3000 (configurable)
  • Replica Servers: 9000+ (basePort + index)

🔄 How It Works

  1. Registry manages service discovery and routing
  2. Middleware handles request forwarding
  3. Load Balancer distributes requests across replicas
  4. Replicas execute the actual RPC methods
  5. Client makes requests through the registry

⚠️ Important Notes

  • Global Registry can only have one instance - multiple instances will throw errors
  • All components use ES modules (import/export)
  • Requires Node.js 16+ for optimal performance
  • Functions should be pure and stateless for best results

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

👨‍💻 Author

Navnath Kadam

🙏 Support

If you find this project helpful, please give it a ⭐ on GitHub!


Built with ❤️ for the Node.js community