Imagine you're using @nestjs/throttler and @nestjs/idempotency together.
Everything works fine until you notice something: replaying an idempotent request still consumes your rate-limit quota.
That's a problem.
A client sends a request with an Idempotency-Key . The server processes it successfully and stores the result. Later, the client retries the same request because it didn't receive the original response.
The whole point of idempotency is to return the previous result without executing the handler again. So why should a replay consume another rate-limit slot?
Let's look at why this happens and how to fix it without implementing your own rate-limiting algorithm.
Why does this happen?
The important thing to understand is NestJS request lifecycle.
Guards run before interceptors.
A simplified request flow looks like this:
Incoming Request | v Guards | v Global Interceptors | v Route Interceptors | v Controller | v Handler
Enter fullscreen mode
Exit fullscreen mode
Now consider our…