7
Back to Problem Dungeon

Rate Limiter

medium

Step 1: Requirements

Requirements

Questions to Ask

  1. Per-user, per-IP, per-API-key, or global? (Per-user with API key, fallback to IP)
  2. What algorithms? (Token bucket, sliding window, fixed window)
  3. Distributed across multiple servers? (Yes — Redis-backed)
  4. Different limits per endpoint or tier? (Yes — free vs paid tiers)
  5. What response on limit exceeded? (429 Too Many Requests with Retry-After header)
  6. 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)

1 / 7 — Requirements