bottleneck

A lightweight, zero-dependency rate limiter and task scheduler for Node.js with built-in Redis clustering support.

Library
npm
v2.19.5
2,005stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
48/100Fair
Development Activity0
Maintenance44
Community48
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
65/100Good
Architecture82
Code Quality72
Innovation80
Learning Curve25

Bottleneck is a zero-dependency task scheduler and rate limiter for Node.js and the browser, designed to throttle API calls without adding meaningful complexity to a codebase. It wraps promise-, async/await-, and callback-based functions alike through submit(), schedule(), and wrap(), queuing jobs and releasing them according to configurable concurrency, minimum time between requests, and reservoir-based quotas.

Beyond single-process use, Bottleneck can synchronize rate limits across multiple Node.js instances via Redis (ioredis or node_redis), using atomic Lua scripts to keep counters consistent even when clients disconnect unexpectedly. This clustering support, along with job priorities, retry hooks, batching, and a full event system for debugging, makes it a common choice for applications that need reliable throttling both locally and at scale.

What You Get

  • A promise/async-await/callback-agnostic API (schedule(), wrap(), submit()) that rate-limits usage without rewriting the wrapped function
  • Concurrency and timing controls (maxConcurrent, minTime, reservoir) to model per-second, per-minute, or bursty rate limits
  • Distributed rate limiting across processes and servers via Redis (ioredis or node_redis) with atomic Lua-script coordination
  • Job priorities, weights, retries, and expiration for fine-grained control over queue order and failure handling
  • A Group helper for managing per-key limiters (e.g., one limiter per API user) without manual bookkeeping
  • Batching support (Batcher) to coalesce many small calls into fewer batched requests

Common Use Cases

  • Throttling calls to third-party APIs (payment processors, SaaS platforms) that enforce strict per-second or per-minute rate limits
  • Coordinating rate limits across multiple worker processes or horizontally scaled servers sharing one external API quota
  • Limiting concurrent database or filesystem operations to avoid overwhelming a downstream resource
  • Smoothing bursty webhook or event-processing workloads into a steady, predictable request rate

Under The Hood

Architecture Bottleneck follows a layered design: the public Bottleneck class exposes submit/schedule/wrap and delegates queue management to a Queues module, job lifecycle to a Job module, and rate-limit state to a pluggable datastore — a local in-process store for single-process use, or a Redis-backed store for distributed use. Jobs pass through a queue-and-drain cycle that consults the active datastore before releasing a job for execution, with state and events tracked by dedicated subsystems. The Redis-backed datastore swaps in Lua scripts for every state-mutating operation, making cross-process coordination atomic without needing distributed locks. This datastore abstraction is the core seam: switching from local to Redis-backed storage changes only what backs concurrency/timing state, while the public API and job lifecycle stay identical — a clean application of the strategy pattern to state storage. Were the Lua-script contract to change, the local and Redis implementations would need to evolve in lockstep.

Tech Stack Written in CoffeeScript and compiled to two published bundles — a full Node.js build and a lighter browser bundle without Redis support — with zero runtime dependencies. Distributed coordination targets Redis via either of the two dominant Node Redis clients as optional integrations, using hand-written Lua scripts assembled at build time rather than a query builder. Type definitions are hand-authored from a template rather than derived from TypeScript source. Testing runs against real Redis connections in continuous integration rather than mocking the datastore, and a dedicated bundler pipeline produces the browser build.

Code Quality The test suite is extensive and exercises the distributed-coordination paths against real Redis backends rather than mocks, giving strong confidence in cluster behavior specifically. Error handling is explicit and typed through a dedicated error class, and job failures, drops, and retries are modeled as first-class states rather than being swallowed silently. Naming is consistent, with a clear naming convention marking the boundary between the public API and the internal datastore interface. Inline comments are sparse throughout the source, and there is no linter or formatter configuration checked into the repository.

API Design The headline design choice is transport-agnostic scheduling — the same limiter object can rate-limit promise-returning, async/await, and Node-style-callback functions, so adopting the library requires no rewrite of existing call sites. The wrapping helper in particular offers near-zero-boilerplate adoption, and the per-key group helper removes the manual bookkeeping of tracking one limiter per key, including disposing of idle limiters automatically. The reservoir-based options give a well-thought-out vocabulary for modeling everything from simple per-second caps to complex rolling or periodic quotas without hand-rolled timer logic. Documentation is unusually thorough, with a full option reference, a lifecycle explanation, an event list, and a dedicated section anticipating common misuse.

Used by 5 apps in this directory

TypeScript
100%
Other

Dub

Marketing · Analytics

24,676

The open-source link attribution platform for short links, conversion tracking, and affiliate programs — powering 100M+ clicks monthly.

View details
80
Repo Health
78
Technical
62
Dependency
Built with
TypeScript100%
Updated 2 days ago
TypeScript
91%
Apache 2.0

Helicone

Monitoring · AI Development · Analytics

6,133

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
69
Repo Health
81
Technical
65
Dependency
Built with
TypeScript91%
Updated 1 weeks ago
TypeScript
95%
MIT

OmniRoute

AI Agents

62,058

A free, open-source AI gateway connecting Claude Code, Codex, Cursor, Cline, and Copilot to 237 AI providers (90+ free) through one endpoint, with automatic fallback and token-compression to stretch free-tier limits further.

View details
86
Repo Health
70
Technical
74
Dependency
Built with
TypeScript95%
Updated yesterday
TypeScript
99%
Other

Papermark

Digital Signiture · File Storage

9,115

Open-source DocSend alternative with page-by-page analytics, secure data rooms, and custom domains for document sharing.

View details
84
Repo Health
63
Technical
67
Dependency
Built with
TypeScript99%
Updated 1 weeks ago
TypeScript
79%
AGPL 3.0

Postiz

Social Media · Automation

35,528

The agentic social media scheduler — AI-powered content creation, 33-platform posting, and team workflows, all self-hosted.

View details
91
Repo Health
70
Technical
63
Dependency
Built with
TypeScript79%
JavaScript12%
Updated 3 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search