@stack-hq/scaling
v1.0.0
Published
Load balancing (round-robin, weighted round-robin, least-connections, random) and consistent hashing.
Downloads
87
Maintainers
Readme
@stack-hq/scaling
Load balancer with 4 selection algorithms (round-robin, weighted round-robin, least-connections, random) and a consistent-hash ring for stable key-to-node distribution.
Install
npm install @stack-hq/scalingUsage
import { LoadBalancer, ConsistentHashRing } from "@stack-hq/scaling";
const lb = new LoadBalancer(
[{ id: "a", host: "10.0.0.1", port: 3000 }, { id: "b", host: "10.0.0.2", port: 3000 }],
"least-connections"
);
const backend = lb.next();
const ring = new ConsistentHashRing(["cache-1", "cache-2", "cache-3"]);
const shard = ring.getNode("user:42"); // stable across node additions/removalsLicense
MIT
