KatInterview

Building a High-Throughput Distributed Rate Limiter

System DesignModel answer
MediumModel answerSystem Designdistributed-systemsrate-limitingcaching

Last updated

Design a multi-region rate limiting system that handles millions of requests per second with low latency while managing hot keys and partition failures.

You need to architect a distributed system that enforces rate limits on API traffic across a global infrastructure. The system evaluates incoming requests against configurable policies and decides whether to accept or reject them based on sliding time windows.

Context

Your organization runs high-traffic APIs serving millions of users. You need protection against abuse, resource exhaustion, and uneven load. The rate limiter must operate as part of the request path, making allow/deny decisions based on rules like "maximum 1,000 requests per minute per user" or "50 requests per second per IP address."

What You Need to Design

Your system should support:

Core Capabilities:

  • Evaluate requests against multiple rule types simultaneously (by user ID, tenant, IP, endpoint)
  • Return allow/deny decisions along with metadata (remaining quota, reset time)
  • Apply updates to rate limit rules without restarting services

Performance & Reliability Targets:

  • Handle 10 million decisions per second across all regions
  • Keep decision latency under 5 milliseconds at p99
  • Maintain 99.999% uptime
  • Continue operating through node crashes, network splits, and sudden traffic surges
  • Handle scenarios where a single identifier (hot key) receives disproportionate traffic

Key Design Areas to Address

Explain your choices for:

  1. Algorithm selection: Which rate limiting algorithm works best given memory and accuracy requirements?
  2. Distribution strategy: How do you partition state across machines and prevent load imbalance?
  3. Hot key handling: What happens when one user or IP generates extreme traffic that would overwhelm a single node?
  4. Latency vs accuracy: How do you achieve sub-5ms decisions while maintaining reasonably accurate counts across distributed nodes?
  5. Failure behavior: When components fail, should the system allow all traffic (fail open) or block it (fail closed)?

Discuss trade-offs explicitly and quantify your design where possible.

Hints

Hint 1

Making a remote call to check every request will consume your entire latency budget—consider where decisions actually happen

Hint 2

Perfect accuracy across distributed nodes requires synchronization that is too slow; small overshoot is usually acceptable

Hint 3

The hottest keys are often the ones already over their limit—caching denial decisions eliminates most hot key traffic

Hint 4

Consistent hashing distributes keys uniformly but not load uniformly; you need additional techniques when one key dominates