Step 1: Requirements
Requirements
Questions to Ask
- Per-user, per-IP, per-API-key, or global? (Per-user with API key, fallback to IP)
- What algorithms? (Token bucket, sliding window, fixed window)
- Distributed across multiple servers? (Yes — Redis-backed)
- Different limits per endpoint or tier? (Yes — free vs paid tiers)
- What response on limit exceeded? (429 Too Many Requests with Retry-After header)
- Burst handling? (Token bucket allows short bursts)
Functional Requirements
- Rate limit incoming HTTP requests
- Support multiple algorithms (token bucket, fixed window, sliding window log)
- Configure limits per tier (free: 100/min, paid: 1000/min)
- Return 429 with Retry-After when exceeded
- Work across multiple server instances (distributed)
Non-Functional Requirements
- Sub-millisecond overhead per request
- Atomic operations (no race conditions on counters)
- Graceful degradation if Redis is down (allow requests, log warning)