Design Rate Limiter

Medium

Design a distributed rate limiting service that protects APIs from abuse and overload. Support multiple algorithms (token bucket, sliding window), per-user and per-API limits, distributed counting across multiple data centers, and real-time configuration changes at the scale of millions of requests per second.

What to design

  1. What are the core functional requirements for a distributed rate limiter?
  2. What are the non-functional requirements? Consider decision latency, accuracy, and availability.
  3. Design the APIs — rate limit check (inline), rule management, and usage queries.
  4. Explain the token bucket algorithm and when you would use it.
  5. Explain the sliding window algorithms and how they compare to fixed windows.
  6. How would you implement distributed rate limiting across multiple servers?
  7. How would you handle rate limiting across multiple data centers?
  8. How would you propagate rule changes in real-time to all rate limiter nodes?
  9. How should the rate limiter behave when it itself is experiencing failures?