NestJS API Quota Management: meet nestjs-quota
If you run a multi-tenant API on NestJS, you probably need more than a rate limiter. You need to answer "may this request proceed?" against several limits at once (per user per minute, per tenant per day, per tenant per month) and "how much has each tenant actually used?" for billing and dashboards. nest-quota is an open-source package that does both. It checks and consumes all the relevant…
NestJS API developers managing multiple quotas simultaneously requires more than just a rate limiter. The nest-quota package offers a solution that handles both quota enforcement and usage metering in one atomic operation. This ensures no partial charges and helps avoid race conditions, double charging on retries, and other issues.
The package works across multiple servers using Redis and provides decorators, a guard, and interceptor for easy integration. It supports plan-based dynamic limits and configurable fail-open or fail-closed behavior. The core has zero runtime dependencies, and Redis is optional.
Atomic multi-policy consumption is achieved by running all policies as a single Lua script in Redis, ensuring either all buckets are incremented or none are. This eliminates race conditions, partial charges, and double charging on retries. Idempotent retries are supported by using an idempotencyKey, preventing double charges.
Reservations can be made for operations with uncertain costs, holding capacity until the outcome is known. The interceptor allows post-handler metering when the real usage amount is only known after the request processing.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.