Best lists

8 Best Rate Limiting Libraries in 2026 (Node.js & Beyond)

The right rate limiter depends on one question: are you limiting requests coming in, or requests going out? Pick the wrong side and the library will not help at all.

Cysoro Security TeamPublished · 11 min read
GET /api/users — 200 GET /api/users — 200 RateLimit: 2 / 100 left 429 Too Many Requests BEST LISTS Best ratelimitinglibraries Inbound or outbound? Pick right.
Quick answer

The best rate limiting library for most Node.js APIs is express-rate-limit: simple Express middleware, about 15 KB, with standard RateLimit headers and Redis store adapters for multi-server setups. For distributed multi-server limiting, use rate-limiter-flexible with Redis; for throttling your app's outbound calls to external APIs, use Bottleneck; for serverless and edge runtimes, use @upstash/ratelimit. All eight libraries here are free and open source.

Key takeaways

  • express-rate-limit is the best default for Express APIs; rate-limiter-flexible is the best choice once you run multiple servers behind a load balancer.
  • Inbound and outbound limiting are different jobs — Bottleneck throttles calls your app makes, not calls it receives.
  • Always send standard RateLimit headers and a 429 with Retry-After, and store counters in Redis the moment you have more than one server instance.

An API without a rate limit is an open invitation. Attackers can guess passwords at machine speed, scrape every record your endpoints will return, or trigger thousands of paid text messages in minutes — all with requests that look perfectly valid. OWASP lists this risk as API4:2023, Unrestricted Resource Consumption, in its API Security Top 10.

The fix is a rate limiting library, but the right one depends on a question most guides skip: are you limiting requests coming in, or requests going out? Pick the wrong side and the library will not help at all. This list covers both, plus the serverless and framework-specific options, so you can match the tool to the job.

What is rate limiting, and why does it matter?

Rate limiting caps how many requests a client can make in a window of time. When the cap is hit, the server answers with HTTP 429 Too Many Requests, usually with a Retry-After header telling the client when to try again. That turns an unlimited guessing game into a bounded one.

It protects against three different harms. Brute force and credential stuffing slow to a crawl when logins are capped. Scraping and abuse stop being cheap when each client gets a fixed quota. And cost spikes — such as a chatbot feature or SMS flow triggered thousands of times — stay bounded because the meter stops at the limit.

Rate limiting is necessary, not sufficient. It slows attackers; it does not stop a determined one. Pair it with multi-factor authentication, account lockout, input size limits and spending caps on third-party services. Our guide to how to know if your phone is hacked shows what account takeover looks like from the victim's side.

Inbound vs outbound: two different jobs INBOUND — protect your APIClients call you. You cap them.Stops brute force, scraping,overload and cost spikes.express-rate-limit · rate-limiter-flexible OUTBOUND — protect your quotasYou call external APIs. You paceyourself so you stay undertheir limits.Bottleneck · p-limit · throttled-queue Ask first: who is being limited, and in which direction? Most APIs need an inbound limiter. Apps that call Stripe, OpenAI or GitHub need an outbound one too.
Inbound limiting protects your API; outbound limiting protects your external quotas. Illustration by Cysoro.

How did we choose these rate limiting libraries?

We required four things. First, the library must solve a real, distinct job — inbound, outbound, distributed, serverless or framework-specific — rather than duplicating another entry. Second, it must be actively used in production, with a maintained codebase or a maintained fork. Third, it must support the features production systems need: shared state, standard headers, and sensible defaults. Fourth, it must be free and open source.

We excluded libraries that only work in memory with no store option, that have no documentation beyond a readme, and that duplicate a stronger entry without a distinct advantage.

The 8 best rate limiting libraries compared

express-rate-limit is the default for Express APIs, rate-limiter-flexible is the distributed upgrade, and Bottleneck is the outbound specialist. The rest fill serverless, framework and concurrency niches.

LibraryBest forDirectionRedis supportPrice
express-rate-limitExpress APIs, best defaultInboundVia store adapterFree (MIT)
rate-limiter-flexibleDistributed, multi-serverInboundBuilt-inFree (ISC)
BottleneckOutbound throttlingOutboundBuilt-in clusteringFree (MIT)
@upstash/ratelimitServerless and edgeInboundUpstash Redis (HTTP)Free tier; paid plans
express-slow-downSlowing instead of blockingInboundVia store adapterFree (MIT)
p-limitConcurrency limitsOutboundNoFree (MIT)
throttled-queueSimple interval queuesOutboundNoFree (MIT)
@nestjs/throttlerNestJS appsInboundVia storage adapterFree (MIT)

Weekly download figures in 2026 comparisons put express-rate-limit at roughly 4 million, rate-limiter-flexible at roughly 1.8 million and Bottleneck at roughly 1.2 million. Downloads are a popularity signal, not a quality ranking — the right library is the one that matches your architecture.

1. express-rate-limit — best for Express APIs

express-rate-limit is the standard rate limiting middleware for Express, and the default choice for a normal Express API. It takes about ten lines to set up, needs no infrastructure on a single server, and covers IP-based limits with no dependencies beyond Express itself.

Its configuration follows the IETF rate limit header drafts: set standardHeaders to 'draft-8' for the current combined RateLimit header and a RateLimit-Policy header, and disable the legacy X-RateLimit-* headers. The classic example limits each IP to 100 requests per 15 minutes. For multiple servers, pair it with the rate-limit-redis store adapter.

Key features:

  • Express middleware with window, limit, skip and custom key options
  • Standard RateLimit headers (draft-6, draft-7 and draft-8) and Retry-After on blocked requests
  • IPv6 subnet handling and custom stores, including Redis and Memcached
  • Plays well with express-slow-down for graduated responses

Pros: simplest setup; smallest bundle at about 15 KB; best documentation. Cons: Express-only; fixed-window by default; in-memory store does not share state across servers. Pricing: free, MIT licensed. Who should pick it: any single-server or small Express API that needs inbound limiting today.

2. rate-limiter-flexible — best for distributed limiting

rate-limiter-flexible is designed for production multi-server setups from the start. It supports Redis, Memcached, MongoDB and Postgres as backing stores, and offers true sliding windows, token buckets and multi-tier limits that express-rate-limit does not.

Its strength is flexibility: you can stack limiters — for example, a per-IP limit, a per-user limit and a per-endpoint limit — and combine them with blocking durations. A typical setup allows 100 points per 15 minutes in Redis, then blocks for a minute when exceeded. That makes it the right choice when rate limiting is part of your product surface, such as paid plan quotas or login defense.

Key features:

  • Built-in Redis, Memcached, MongoDB and Postgres stores
  • True sliding window, token bucket and leaky bucket algorithms
  • Stackable limiters and block durations after repeated abuse
  • Framework-agnostic: works with Express, Fastify, Koa and raw Node.js

Pros: most flexible algorithms; built-in distributed stores; framework-agnostic. Cons: more code to configure; larger bundle at about 40 KB. Pricing: free, ISC licensed. Who should pick it: teams running multiple servers, paid API quotas, or anything beyond a fixed window.

3. Bottleneck — best for outbound throttling

Bottleneck solves the opposite problem: controlling how fast your application sends requests to external services. If you call a third-party API that enforces its own limits, Bottleneck paces your calls with minTime between jobs, maxConcurrent limits, reservoir intervals for bursts, and priorities and retries.

A typical setup, per Bottleneck's documentation, runs 3 requests per second with minTime: 333, or caps concurrency while spacing calls. It also supports clustering across multiple Node.js instances through Redis, using strictly atomic operations. Use it when your app calls Stripe, OpenAI, GitHub or a payment processor from several workers.

Key features:

  • minTime, maxConcurrent, reservoir intervals and job priorities
  • Clustering via Redis, Redis Cluster and Redis Sentinel
  • Retries, batching and grouping for complex job flows
  • Zero dependencies; works in Node.js and the browser

Pros: best outbound throttling; precise burst control; battle-tested. Cons: the original package (2.19.5) is no longer actively maintained — a fork, @sderrow/bottleneck, carries current fixes. Pricing: free, MIT licensed. Who should pick it: any app that must stay under an external API's quota.

4. @upstash/ratelimit — best for serverless and edge

@upstash/ratelimit is built for runtimes where in-memory counters cannot work: Vercel, Cloudflare Workers and AWS Lambda, where each invocation may run on a different instance. It stores counters in Upstash Redis over HTTP, so no persistent connection is needed.

It supports fixed window, sliding window and token bucket algorithms, with a simple API such as a sliding window of 5 requests per 15 minutes for a login endpoint. The free tier covers small projects, and paid plans scale with usage. It is the right choice when your API has no long-lived server at all.

Key features:

  • HTTP-based Redis counters — no persistent connections
  • Fixed window, sliding window and token bucket algorithms
  • Works on Vercel, Cloudflare Workers and AWS Lambda
  • Analytics and per-key limits built in

Pros: only practical option for true serverless; simple API; analytics included. Cons: tied to Upstash Redis; paid beyond the free tier. Pricing: free tier available; paid plans by usage. Who should pick it: serverless and edge APIs with no persistent server.

5. express-slow-down — best for slowing instead of blocking

express-slow-down is the companion to express-rate-limit, from the same project. Instead of rejecting requests with a 429, it adds a growing delay to each response once a client passes a threshold — a gentler response that frustrates bots without locking out a real user who clicked too fast.

Use it on endpoints where a hard block would hurt, such as a search box or a public page, and reserve hard limits for logins and paid actions. It shares the same store adapters as express-rate-limit, so the two can run together with consistent state.

Key features:

  • Progressive delays instead of hard blocks
  • Same store adapters as express-rate-limit, including Redis
  • Configurable delay, window and skip logic

Pros: user-friendly for borderline traffic; pairs with express-rate-limit. Cons: Express-only; delays consume server resources. Pricing: free, MIT licensed. Who should pick it: public endpoints where a block would punish real users.

6. p-limit — best for concurrency limits

p-limit is the smallest tool on this list, and the most focused: it limits how many promises run at the same time. Wrap an async function with pLimit(5) and at most five calls run concurrently; the rest wait in a queue. It does not limit requests per second — it limits simultaneous work.

That makes it ideal for parallel fetching, image processing or database calls, where the risk is too many things at once rather than too many per minute. Combine it with Bottleneck when you need both concurrency and a per-second cap.

Key features:

  • One function: limit concurrent promise execution
  • Tiny, dependency-free, TypeScript-friendly
  • Works anywhere promises work, in Node.js and browsers

Pros: simplest possible API; near-zero overhead. Cons: no time-based limiting; no distributed state. Pricing: free, MIT licensed. Who should pick it: anyone throttling parallel async work rather than request rates.

7. throttled-queue — best for simple interval queues

throttled-queue does one thing: it runs queued functions at an even interval, such as 10 per second, spaced out rather than bursty. It is the simplest outbound throttle for scripts, scrapers and batch jobs that just need a steady pace.

It has no Redis support, no priorities and no retries — and that is the point. For a small script that calls an API in a loop, throttled-queue is less code than Bottleneck and easier to reason about. Outgrow it when you need clustering or burst control.

Key features:

  • Evenly spaced execution at a set interval
  • Minimal API: create a queue, push functions into it
  • No dependencies, no server, no configuration files

Pros: simplest outbound queue; ideal for scripts and batch jobs. Cons: no clustering, priorities or retries. Pricing: free, MIT licensed. Who should pick it: small scripts and batch jobs that need a steady pace.

8. @nestjs/throttler — best for NestJS apps

@nestjs/throttler is the official rate limiting module for NestJS. It adds declarative limits with decorators — set a limit per controller or per route, choose a time-to-live, and the module handles the rest. It supports multiple throttlers at once, so a global limit and a strict login limit can coexist.

Storage is pluggable: the default in-memory store works for a single instance, and a Redis-backed storage adapter covers multi-server deployments. If you already build with NestJS, this is the idiomatic choice rather than bolting on Express middleware by hand.

Key features:

  • Decorator-based limits per route, controller or globally
  • Multiple named throttlers with different limits and windows
  • Pluggable storage, including Redis adapters
  • Built-in guards that integrate with NestJS authentication

Pros: idiomatic for NestJS; declarative and testable. Cons: NestJS-only; less flexible than rate-limiter-flexible. Pricing: free, MIT licensed. Who should pick it: any team already building with NestJS.

Which rate limiting algorithm should I use?

Most production limiters use one of four algorithms. Fixed window is the simplest: count requests in a set period, then reset. Token bucket is the best default for most APIs: tokens refill at a steady rate, and a request spends one — which allows short bursts while holding the average rate.

Sliding window counts requests over a rolling period, so it smooths the burst that fixed windows allow at boundaries. Leaky bucket processes requests at a constant rate, queueing the excess — good for smoothing traffic, bad when a queue grows unbounded. Start with token bucket, switch to sliding window when fairness at window edges matters, and use leaky bucket only when you genuinely need a constant output rate.

Four algorithms, one default Fixed window100 per 15 min,then resetSimple; bursts atthe boundary Token bucketTokens refillsteadily; burstsallowed up tothe bucket size Sliding windowRolling count;no boundarybursts; fairer,needs more state Leaky bucketConstant outputrate; queuecan grow —cap the queue Default: token bucket. Fairer: sliding window. rate-limiter-flexible supports all four; express-rate-limit defaults to a fixed window.
Rate limiting algorithms compared. Illustration by Cysoro.

How do I choose the right rate limiting library?

Answer three questions. First, inbound or outbound? Inbound means express-rate-limit, rate-limiter-flexible, @upstash/ratelimit or @nestjs/throttler. Outbound means Bottleneck, p-limit or throttled-queue. Second, how many servers? One server can use in-memory counters; two or more need Redis. Third, which framework? Express, NestJS and serverless each have an idiomatic pick on this list.

Then set limits per endpoint, not one global limit for everything. Logins get the strictest cap, public reads get a generous one, and paid or expensive actions get a quota tied to the plan.

A single global limit either blocks real users or leaves the sensitive endpoints open. For the wider security picture, work through our small business cybersecurity checklist.

What mistakes should I avoid with rate limiting?

The most common mistake is counting by IP alone. Behind a corporate NAT or a shared proxy, hundreds of real users share one address — and one attacker can rotate through many. Count per account or per API key first, and use IP as a supporting signal.

Other mistakes are easy to make and hard to notice. Forgetting trust proxy behind a load balancer means every request appears to come from the proxy's own address, so one user trips the limit for everyone.

Returning a 429 without a Retry-After header leaves clients guessing. And limiting only the API while leaving the login page, password reset and signup flows unprotected hands attackers the easiest targets. Check your own site's headers with our free security headers checker.

The bottom line

For most Node.js APIs, start with express-rate-limit: ten lines, standard headers, and a Redis store when you scale. Move to rate-limiter-flexible when you need distributed state or sliding windows, add Bottleneck for outbound calls, and reach for @upstash/ratelimit on serverless.

Whichever library you pick, the discipline matters more than the code: per-endpoint limits, per-account counting, standard headers, and a 429 with a Retry-After.

Frequently asked questions

What is the best rate limiting library for Node.js?

express-rate-limit is the best default for Express APIs: it is the standard middleware, takes about ten lines to set up, and supports Redis stores for multi-server setups. If you run multiple servers or need sliding windows and per-user quotas, rate-limiter-flexible is the stronger choice.

What is the difference between inbound and outbound rate limiting?

Inbound limiting caps requests other people make to your API, protecting you from brute force, scraping and overload. Outbound limiting caps requests your app makes to external APIs, so you do not exceed their quotas. express-rate-limit and rate-limiter-flexible are inbound tools; Bottleneck is an outbound tool.

Do I need Redis for rate limiting?

Not on a single server — in-memory counters work fine. The moment you run two or more server instances behind a load balancer, you need shared state, and Redis is the standard choice. Without it, each instance enforces its own limit and an attacker can multiply their quota by the number of servers.

What is a 429 response?

HTTP 429 Too Many Requests is the standard response when a client exceeds a rate limit. It should include a Retry-After header telling the client when to try again, and ideally RateLimit headers showing the limit, remaining quota and reset time.

What is the difference between a fixed window and a sliding window?

A fixed window counts requests in a set period, such as 100 per 15 minutes, then resets — which allows a burst at the boundary. A sliding window counts requests over a rolling period, so bursts at window edges are smoothed out. Sliding windows are fairer but need more state.

Is Bottleneck still maintained?

The original Bottleneck package (2.19.5) has not been updated in years, and a maintained fork, @sderrow/bottleneck, now exists with modern JavaScript, Redis v4+ support and promise-only APIs. If you start a new project with Bottleneck, use the fork or check its maintenance status first.

How do I rate limit login endpoints?

Use a stricter limit than the rest of your API — for example, 5 failed attempts per 15 minutes per account — and count per account, not just per IP, so an attacker cannot spread guesses across addresses. Combine it with multi-factor authentication and account lockout after repeated failures.

Can I use rate limiting in serverless functions?

Yes, but in-memory counters do not work because each invocation may run on a different instance. Use an HTTP-based limiter such as @upstash/ratelimit, which stores counters in Upstash Redis and works on Vercel, Cloudflare Workers and AWS Lambda without persistent connections.

Sources

  1. express-rate-limit — Configuration reference
  2. Bottleneck — npm package documentation
  3. PkgPulse — Best Express Rate Limiting Packages 2026
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against the express-rate-limit configuration reference, Bottleneck's npm documentation and a 2026 comparison of the npm packages.

How we write and fact-check →

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free