System Design Problems interview question · Most asked

Design a rate limiter for a public API.

Design Asked in Backend Engineer · Tech Lead · Full Stack Engineer · Forward Deployed Engineer (FDE) interviews

Members can save this page, take notes and track progress. See membership · Sign in

Summary

Identify clients (API key, user, IP), choose an algorithm (token bucket for bursts with a steady rate, sliding window for strict limits), store counters in a fast shared store such as Redis with atomic operations, enforce at the API gateway or middleware, and return 429 Too Many Requests with Retry-After and rate-limit headers.

Longer Answer

  • Algorithms: fixed window (simple, bursty at edges), sliding window log or counter (accurate), token bucket (allows bursts, smooth average), leaky bucket (smooths output).
  • Distributed: Redis with Lua scripts or INCR + EXPIRE for atomicity; local in-memory buckets with periodic sync when latency matters more than precision.
  • Tiers: per-plan limits, per-endpoint limits for expensive operations, global limits to protect the system.
  • Failure mode: decide whether to fail open (allow) or closed if Redis is down; usually open with a local fallback limit.
  • Clients: document limits; headers RateLimit-Limit, RateLimit-Remaining, Retry-After.

Key Points

  • Identify clients; pick an algorithm.
  • Atomic counters in a shared store.
  • 429 with Retry-After and headers.
  • Tiers per plan and endpoint.
  • Decide fail-open vs fail-closed.

Explanation

What interviewers look for

Algorithm trade-offs, distributed correctness and client experience.

More System Design Problems questions

← All System Design Problems questions

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake