Urgent.News

What's breaking now, across thousands of outlets.

Tech

NestJS Rate Limiting: In-Memory vs Redis vs Postgres

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…

Cross-posted from my blog. The full article, with any updates, lives on fabwaseem.com. I tested the rate limiting features in NestJS 12 using three different storage backends: in-memory, Redis, and PostgreSQL. All tests were conducted on an 8 vCPU/16 GB Linux VM on November 6, 2026, using Node.js 24.22.1, NestJS 12.3.3, and @nestjs/throttler 6.7.1.

Redis 7.2.11 (without persistence) was used for Redis storage, and PostgreSQL 18.6 was used for PostgreSQL storage. The limit for all tests was set to 100 requests per 60 seconds, with the tracker keyed on the x-forwarded-for header to ensure localhost tests did not share the same IP. The three metrics measured were the p50 and p95 latency of allowed requests, whether request 101 returns a 429 response, and whether two Nest processes using the same storage still stop at 100 total requests.

The in-memory storage is the default setup, which is sufficient for a single process but fails to provide accurate rate limiting when scaled out across multiple processes. For Redis storage, the @nestjs-redis/throttler-storage package was used, which implements the ThrottlerStorage interface with an atomic Lua script to increment the counter.

PostgreSQL storage was implemented as a custom storage solution, where each key is stored in a throttler_hits table with hits, expires_at, is_blocked, and block_expires_at columns. In all tests, the limit was set to 100 requests per 60 seconds, and the x-forwarded-for header was used as the tracker to ensure accurate rate limiting across multiple instances.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

The 7 VS Code Settings I Change on Every New Machine (and Why the Defaults Slow You Down)

I set up a new machine last month and counted how long it took before VS Code felt like mine. Answer: about 15 minutes, most of it spent changing the same seven settings I change every single time.

  • editor.fontLigatures: true Enhances legibility by merging symbols like != into a single character
  • editor.formatOnSave: true Automatically formats code upon saving, preventing formatting disputes
  • editor.tabSize: 2 (with editor.detectIndentation: false) Ensures consistent indentation across files

I Tried Learning in Public for 30 Days — the 3 Things That Actually Worked

A month ago I decided to learn in public. The idea is simple: instead of studying quietly and showing people a finished project at the end, you post what you are learning every day, mistakes included…

  • Strangers corrected the author's mistakes, enhancing learning
  • Daily posting streak maintained consistency, even on tough days
  • Learning journey turned into portfolio aiding job interview

More from Friday 6 November →