Design a Distributed Rate Limiter

Quick Overview

Design a rate limiting service for an API gateway. Compare token bucket, leaky bucket, and sliding window algorithms. Cover distributed coordination across data centers and handling edge cases like clock skew.

Google
System Design
Software Engineer
Google
Software Engineer
System Design Round
System Design
Medium

0


Design a rate limiting service for an API gateway. Compare token bucket, leaky bucket, and sliding window algorithms. Cover distributed coordination across data centers and handling edge cases like clock skew.

Google asks this in system design rounds framed around an API gateway serving Cloud style multi-tenant traffic, where every request pays the cost of the limit check. The interviewer wants a justified algorithm choice, a design for counters shared across data centers, and a concrete answer for clock skew and store outages.

What the Interviewer Expects
  • Compare token bucket, leaky bucket and sliding window with their burst behavior
  • Model per-tenant limits and where the configuration lives
  • Store bucket state centrally with atomic refill-and-consume updates
  • Handle clock skew by using one time source (the store's clock) for refill math
  • Explain cross-region coordination and the overshoot you accept
  • Decide fail-open vs fail-closed and how to degrade gracefully
Key Topics to Cover
Token bucket
Leaky bucket
Sliding window
Clock skew
Multi-tenancy
Distributed state
How to Approach This
  1. Start by clarifying functional and non-functional requirements with the interviewer.
  2. Estimate the scale: QPS, storage, bandwidth. This drives your design decisions.
  3. Draw a high-level architecture first, then deep dive into 1-2 critical components.
  4. Discuss trade-offs explicitly (e.g., consistency vs availability, SQL vs NoSQL).
  5. Address failure scenarios, monitoring, and how the system handles 10x traffic spikes.
Possible Follow-up Questions
  • How would you cut the latency of checks that cross regions?
  • How do you roll out a lower limit for one tenant without a deploy?
  • What metrics tell you the limiter itself is causing errors?
  • How would you limit by concurrent connections instead of request rate?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • Functional Requirements:
    • Implement a distributed rate limiter using a token bucket algorithm.
    • Support multi-tenancy to handle different rate limits for various users.
    • Provide APIs to...
Capacity Estimation

Assuming Perplexity has 10,000 active users querying the LLM API:

  • Each user makes an average of 10 requests per minute, leading to a total of:
    • Total requests per minute = 10,000 users * 10 reque...

Submit Your Answer
Markdown supported