Technical Questions

How would you design a distributed rate limiter for an API?

Why Interviewers Ask This

Evaluates distributed systems thinking: atomicity, latency overhead, Redis vs local memory, and failure modes.

What a Strong Answer Looks Like

  • Clarifies requirements (per-user/IP, global vs regional, strictness).
  • Compares Token Bucket / Sliding Window algorithms.
  • Addresses Redis atomic Lua scripts and fail-open vs fail-closed.

Answer Framework: Clarify -> Algorithm -> Distributed Store -> Failure Mode

  1. 01.Scope QPS, latency budget, and rule granularity.
  2. 02.Choose Token Bucket or Sliding Window Counter.
  3. 03.Use Redis with atomic Lua/INCR+EXPIRE and discuss fail-open.

Example Answer

“I'd start by clarifying whether limits are per-user, per-IP, or per-API key and our latency budget. For most APIs, a Token Bucket or Sliding Window Counter in Redis hits the sweet spot between memory efficiency and burst handling. Using a Redis Lua script keeps the check-and-decrement atomic in a single round trip. Finally, I'd configure the gateway to fail-open if Redis is temporarily unreachable so a cache hiccup doesn't take down the entire product.”

Common Mistakes

  • Forgetting race conditions between read and write.
  • Not mentioning what happens if the rate-limiter store goes down.

Ready to test your own answer?

Deliver your response aloud and get instant AI critique on structure and clarity.

How would you design a distributed rate limiter for an API?
Clarify -> Algorithm -> Distributed Store -> Failure Mode
Practice this question