NestJS Rate Limiting for Spring Developers: The Wrong User Blocked

30 September 2026 nestjstypescriptnodejsjavaspring-bootsecurity
PDF The design sheet The full architecture and the verified references. Free, no email.
Thumbnail for NestJS Rate Limiting for Spring Developers: The Wrong User Blocked 4:57
Watch on YouTube, or read on below.
Run this yourself → Clone the repo, docker compose up, and watch it happen

Three requests a minute per client. Behind a proxy, client one used its three and client two’s very first request got 429, on Spring Boot with Bucket4j and on NestJS with the throttler. Both were keyed on the proxy’s address. Measured on 30 September 2026.

How far to trust the proxy

Express with trust proxy set to one hop, and Spring with server.forward-headers-strategy=native, took the address the proxy appended. With trust proxy set to true, or Spring’s framework strategy, the key was the leftmost X-Forwarded-For entry, which the client writes: a client that sent its own header passed six requests out of six. Trust the proxy path you control, and strip client-supplied forwarded headers at the edge.

Which identity

Two signed-in users behind one office address: keyed by address, the second was refused; keyed by the verified user, established by authentication, each had a budget.

Where the count lives

Two instances counting in memory allowed six requests against a limit of three, and a restart reset the count. A counter in Redis allowed three and survived the restart, on both stacks.

The edge of the window

Three per two seconds, a refusal at one second, then a request at 2.2 seconds: Bucket4j allowed it, Nest refused it, because the throttler’s blockDuration defaults to the ttl. Three every two seconds is not one algorithm.

The full code for every measurement is in the repository, and the free design sheet above has the checklist on one page.


Watch next

New videos land on Code with Sam - subscribe there if this was useful.

Get the interview pack

A free, practical pack for engineers preparing for senior backend interviews - the questions that actually get asked, and how to answer them like someone who has done the work.

New articles and videos when they land. No spam, and one click to leave.