// Rate limiting

Rate limiting

Request rate-limiting middleware backed by an in-memory, MongoDB or Redis store.


Rate limiting adds middleware that caps how many requests a client can make in a window. You choose where the counters are stored.

Stores

In-memory

Counters live in the process. Zero setup, but not safe across multiple instances — each replica counts independently. Use it for development or a single-process deployment.

MongoDB

Counters are stored in your existing MongoDB, shared across every instance. No extra infrastructure to run. Recommended for most production deployments.

Redis

Counters live in Redis — fast and distributed. Best when you already operate Redis or need the lowest-latency limiting at high request volumes.

Choosing

StoreMulti-instanceExtra infraUse when
In-memoryNoNoneDev, single process
MongoDBYesNone (reuses your DB)Most production apps
RedisYesRedis serverHigh volume / already on Redis

Configuration

Limits (window and max requests) are read through the config module. Adjust them in .env per environment.

warning

The in-memory store looks fine in development but silently under-counts once you run more than one instance behind a load balancer. Switch to MongoDB or Redis before scaling out.