KatInterview

Building a Distributed Rate Limiting System at Scale

System DesignModel answer
HardModel answerSystem Designdistributed-systemsrate-limitingscalability

Last updated

Design a multi-region rate limiting system handling millions of requests per second with multiple limit dimensions and low latency.

You need to design a distributed rate limiting system that operates across multiple geographic regions and can handle approximately 10 million requests per second during peak traffic. The system must enforce rate limits across several dimensions simultaneously and maintain low latency on the hot path.

Functional Requirements

Your rate limiter must support:

  • Multiple limit dimensions: individual user limits, per-endpoint limits, combined user-and-endpoint limits, and system-wide capacity limits
  • Burst handling: allow short bursts of traffic above the steady-state rate
  • Window semantics: approximate a continuous sliding window rather than fixed time buckets
  • Retry signaling: provide accurate retry-after timing when requests are rejected

Non-Functional Requirements

  • Throughput: sustain 10M requests/second across all regions
  • Latency: add less than 1ms overhead (p99) to request processing
  • Accuracy: bounded overshoot is acceptable for most use cases; a small subset of limits requires strict enforcement
  • Availability: handle node failures, network partitions, and regional outages gracefully

What to Cover

Design and justify your approach for:

  1. Algorithm selection — choose the enforcement mechanism and explain how it provides burst tolerance and smooth rate limiting
  2. System architecture — describe component responsibilities and how decisions are made with minimal latency
  3. Data distribution — explain how you partition state across nodes and handle skewed access patterns
  4. Storage technology — select appropriate storage for different data types and justify throughput feasibility
  5. Consistency model — define what guarantees you provide and how you bound inaccuracy
  6. Failure handling — specify behavior during partial failures and how you prevent both over-blocking and under-limiting
  7. Fair allocation — ensure equitable resource distribution across users and regions
  8. Capacity planning — calculate resource requirements and explain how the system scales with traffic growth
  9. Monitoring — identify the key signals needed to operate the system

Provide concrete numbers, discuss trade-offs, and explain reasoning behind major decisions.

Hints

Hint 1

At 10M requests/second, making a network call for every rate limit check is not feasible—consider how to make decisions locally.

Hint 2

Leasing budgets for time periods allows local decision-making while maintaining coordination for shared limits.

Hint 3

Hot keys like global limits need special handling since they cannot be trivially sharded across nodes.