Rate limiting by IP + user (Express)

2968
0

A single abusive client can ruin your latency budget for everyone else, so I rate limit early rather than trying to ‘detect abuse’ after the outage starts. I combine an IP bucket with a user bucket: IP protects unauthenticated endpoints, user protects authenticated endpoints behind NATs. For small deployments I’ll start in-memory, but once you run multiple instances I back it with Redis so limits are consistent. I’m also explicit about what I’m protecting (login, password reset, search) and I return 429 with x-ratelimit-remaining / x-ratelimit-reset so well-behaved clients can back off. This makes your service more predictable under load and reduces noisy incidents.