Menu

1 / 5

NestJS Rate Limiting: In-Memory vs Redis vs Postgres

DEV Community: security·Waseem Anjum·12 days ago
#xROzjvFT
#devtosecurity#devto#dev#redis#storage
Reading 0:00
15s threshold

Cross-posted from my blog. The original, with any updates, lives on fabwaseem.com .

I shipped a NestJS API with the default @nestjs/throttler storage last year and only noticed the hole when we ran two instances behind a load balancer. Each process kept its own counter, so a client that should have been cut off at 100 requests in a minute quietly got closer to 200. Today I re-tested that on NestJS 12 with three storages on the same box: in-memory, Redis, and Postgres.

What I tested

Everything ran on one 8 vCPU / 16 GB Linux VM on November 6, 2026:

Node.js 24.22.1 , NestJS 12.3.3 , @nestjs/throttler 6.7.1

Redis 7.2.11 with persistence off, via @nestjs-redis/throttler-storage 2.0.1 and the redis 5.12.1 client

PostgreSQL 18.6 with a small custom storage that upserts into one throttler_hits table

Limit: 100 requests / 60 seconds , tracker keyed on x-forwarded-for so localhost tests don't all share 127.0.0.1

I measured three things: p50/p95 latency of allowed requests, whether request 101 returns 429, and…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.