Authentication and SMS OTP routes are high-value targets for credential stuffing and billing abuse. Keeping rate-limit counters in Node.js process memory breaks as soon as traffic scales across multiple instances or a container restarts.
Key Takeaway: Execute fixed-window or sliding-window increments inside an atomic Redis Lua script so key expiration never leaks on worker crash, enforce separate IP and phone/email identity keys on OTP endpoints, and return standard HTTP 429 responses with Retry-After headers.
Separate IP limits from recipient identity limits
Relying solely on client IP either blocks legitimate users behind corporate or mobile carrier NATs or fails completely when an attacker rotates residential proxies against one victim's phone number.
On high-cost routes like Twilio SMS OTP verification, enforce two independent Redis keys before triggering an SMS send: a coarser IP window (for example, 20 requests per 15 minutes) and a tight per-recipient cooldown (for example, 3 OTP dispatches per 10…