API Rate Limiting and Abuse Protection in Express

Per-IP and per-user limits, stricter rules for login, and shared counters that work across servers.
Without rate limits, one script can brute-force logins, scrape your data or run up your AI bill. Limits are cheap insurance.
Layered limits
- A generous global limit per IP for all routes.
- Strict limits on login, sign-up and password reset.
- Per-user limits on expensive endpoints such as AI or exports.
Express example
const loginLimiter = rateLimit({
windowMs: 15 * 60 * 1000,
limit: 10,
standardHeaders: "draft-7",
legacyHeaders: false,
store: new RedisStore({ sendCommand: (...args) => redis.sendCommand(args) }),
});
app.post("/api/auth/login", loginLimiter, login);In-memory limits reset per process and do not work behind a load balancer. Store counters in Redis so every instance enforces the same limit.
Respond helpfully
Return 429 with a Retry-After header and a clear message. Legitimate clients can back off correctly instead of hammering the API.
Beyond rate limits
Combine limits with account lockout after repeated failures, CAPTCHA on suspicious sign-ups, and monitoring for unusual traffic patterns.









