KatInterview

Hierarchical Multi-Tenant Rate Limiter Design

System DesignModel answer
MediumModel answerSystem Designrate-limitingdistributed-systemssystem-design

Last updated

Design a distributed limiter that enforces global, regional, and per-endpoint quotas at 500K RPS with sub-10ms overhead and graceful degradation.

Context

You are designing the traffic-control layer for a large public API platform. Every incoming request must be evaluated against several quota rules at once before it reaches a backend service.

Task

Design a rate limiting service that enforces policies at three tiers simultaneously:

  • Per API key, globally — one budget across the entire worldwide fleet of datacenters.
  • Per datacenter — a regional cap applied to all traffic handled there.
  • Per endpoint path — a cap on a specific route (e.g. /v1/search), possibly scoped per key.

A request is admitted only if every applicable rule still has headroom; otherwise return 429 Too Many Requests.

Requirements

Functional

  • Policies express limits over windows, e.g. 100 requests/minute and 5,000 requests/hour.
  • Rejections return 429; include limit/remaining/reset information.

Non-functional

  • The check itself adds less than 10 ms to the request path.
  • The limiter must stay available during storage failures and must not fail closed — a degraded limiter should not reject legitimate traffic outright.

Scale

  • 500,000 requests/second aggregate across roughly five regions.

What to Cover

  1. How counters and policy configuration are stored for fast lookup.
  2. Where the enforcement decision lives (library, sidecar, or central hop) and why.
  3. How concurrent increments stay correct across many limiter nodes.
  4. What happens when the counter store becomes unreachable.

Hints

Hint 1

Do the math first: how many counter operations per second does a request touching three tiers actually generate, and what does that imply for cross-region calls?

Hint 2

Only increments and comparisons are needed — think about which single-round-trip primitive lets you check several counters and commit them together or not at all.

Hint 3

You cannot keep a global per-key budget perfectly synced within 10 ms across continents. What bounded error are you willing to accept, and how do you split the budget so regions rarely collide?