KatInterview

Design a Low-Latency Distributed Rate Limiting System

System DesignModel answer
MediumModel answerSystem Designrate-limitingdistributed-systemscaching

Last updated

Architect a high-performance, multi-tenant rate limiter capable of enforcing global traffic quotas across millions of requests per second with sub-5ms response times.

Architect a scalable, distributed rate-limiting infrastructure for a multi-tenant platform. The service must sit inline with request processing and enforce complex rate policies across global regions without introducing significant latency.

Core Requirements

  • Multi-Tenancy & Custom Rules: Support customizable rules per client or endpoint (e.g., limits by IP, User ID, or API Key; fixed window or burst controls; soft limits vs. hard blocks).
  • Ultra-Low Latency: Process rate-check evaluation in under 5ms at the 99th percentile ($p99$).
  • High Throughput: Handle millions of requests per second (RPS) distributed across global data centers.
  • Controlled Accuracy vs. Availability: Provide configurable trade-offs between exact quota enforcement (strict consistency) and high availability (eventual consistency/local estimation).

Expected Discussion Points

  1. Overall System Architecture: How application proxies/sidecars coordinate with local and regional rate-limiting nodes.
  2. Data Storage & State Management: How state is partitioned, cached, and updated across data centers without global synchronous locks.
  3. Algorithm Selection: Choosing appropriate algorithms (e.g., Token Bucket, Generic Cell Rate Algorithm, Sliding Window) tailored to local leasing and memory bounds.
  4. Resilience Strategy: Behavior under network partitions, regional outages, or control plane failures (fail-open vs. fail-closed dynamics).

Hints

Hint 1

Consider how local caching and token leasing reduce cross-datacenter round-trips to achieve sub-5ms latencies.

Hint 2

Think about how the choice of rate-limiting algorithm affects memory requirements and the ability to split quotas across distributed nodes.

Hint 3

Distinguish between security-critical rules (e.g., login attempts) and high-volume data APIs when deciding between fail-open and fail-closed strategies.