Menu

1 / 2

Redis rate limiting for Node.js, Express, and OTP endpoints

DEV Community: redis·Deepak Chauhan·about 6 hours ago
#y9l1xQsB
#devtoredis#devto#dev#redis#const
Long article (685 words) — no AI summary yet.
Reading 0:00
15s threshold

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…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.