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
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+EXPIREfor 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
- Design a distributed unique ID generator.
- Design a distributed rate limiter.
- Design a chat application (like WhatsApp or Slack).
- Design a ticket booking system (like Ticketmaster).
- Design a payment system.
- Design a notification system (email, SMS, push).
- Design a social media news feed (like Twitter/X or Instagram).
- Design a URL shortener (like bit.ly).