X-RateLimit-Limit, X-RateLimit-Remaining, and Retry-After.Assuming $N = 250{,}000\text{ RPS}$ global peak traffic, $T = 100{,}000$ active tenants, and $K = 5$ distinct quota buckets per tenant:
Each sliding-window counter stores two 64-bit integers (current + previous window) plus a 64-byte key overhead (~128 bytes total in Redis):
With a $3\times$ safety factor for Redis hash-table overhead and replication buffers:
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:
A request is allowed if and only if $\hat{R}(t) + 1 \le L_{\text{quota}}$.
Synchronizing $50{,}000$ active dirty keys every $\Delta t = 0.5\text{ s}$ at $24\text{ B}$ per compressed delta:
| 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 |
ratelimit_decision_duration_ms, ratelimit_allowed_total, ratelimit_denied_total, ratelimit_fallback_active.ratelimit_fallback_active == 1 for > 2 minutes in any region, or p99 decision latency > 8ms.