Distributed System Design: Global Rate Limiter Service


1. Functional & Non-Functional Requirements

Functional

Non-Functional


2. System Architecture

[Diagram]

3. Back-of-the-Envelope Capacity Math

Assuming $N = 250{,}000\text{ RPS}$ global peak traffic, $T = 100{,}000$ active tenants, and $K = 5$ distinct quota buckets per tenant:

Memory Footprint per Region

Each sliding-window counter stores two 64-bit integers (current + previous window) plus a 64-byte key overhead (~128 bytes total in Redis):

[Formula]

With a $3\times$ safety factor for Redis hash-table overhead and replication buffers:

[Formula]

Sliding Window Approximation Formula

Let $c_{\text{curr}}$ be requests in the current window of length $W$, $c_{\text{prev}}$ be requests in the previous window, and $\alpha \in [0, 1)$ be the elapsed fraction of the current window:

[Formula]

A request is allowed if and only if $\hat{R}(t) + 1 \le L_{\text{quota}}$.

Cross-Region Sync Bandwidth

Synchronizing $50{,}000$ active dirty keys every $\Delta t = 0.5\text{ s}$ at $24\text{ B}$ per compressed delta:

[Formula]

4. Partitioning & Hot-Key Mitigation

Risk Trigger Mitigation
Single tenant exceeds 50k RPS Viral API key or DDoS Gateway batches local increments and flushes every 50ms (reduces Redis ops by 95%)
Redis shard failover Node crash or AZ outage Circuit breaker trips after 3 timeouts (5ms each) -> local in-memory fallback
Clock skew between edge nodes NTP drift > 500ms Window boundaries computed using Redis TIME inside the Lua script

5. Observability & SLO Alerts