code.davidloor.com

Open prompt · 30 min recommended

Design a Rate Limiter

00:00

Target 30:00

Design a Rate Limiter

You have 30 minutes. Sketch the system in this notes pane.

Scope

Functional requirements

Non-functional requirements

Out of scope

Suggested approach

  1. Clarify requirements — hard vs. soft limits, granularity (per-second, per-minute), per-endpoint vs. global, client identifier (IP, user, API key)
  2. High-level design — a middleware layer (at the API gateway or in each service) that checks and updates counters before forwarding requests; shared state in Redis
  3. API + data model — no external API; internally: Redis key ratelimit:{client_id}:{window} with an integer counter and TTL
  4. Storage + caching — Redis is the canonical choice: atomic increment (INCR), TTL-based expiry, sub-millisecond latency; Lua scripts or Redis transactions keep check-and-increment atomic
  5. Bottlenecks + mitigations — single Redis node is a bottleneck; use Redis Cluster or a local sliding-window approximation to reduce cross-node calls

Reference talking points

Your notes

Saved locally · 0 chars