Real-World Production Deep Dives: Distributed Rate Limiter

โš ๏ธ Not yet source-checked. These case studies summarize public engineering posts and talks, and some details may be simplified or wrong. Before you repeat a specific number or design in an interview, check it against the company's own write-up. Found an error, or a source that confirms a section? Add it to the tracking issue. Sourced fixes are the most welcome contribution here.

Deep-dive architectural dissections of how Google (Doorman & Cloud Armor), Netflix (Zuul & Concurrency Limits), Cloudflare (eBPF/XDP), and Stripe (Redis Lua) implement distributed rate limiting and overload protection at multi-million QPS scale.


๐Ÿข Deep Dive 1: How Google Implements Rate Limiting (Doorman & Cloud Armor)

1. Production Context & Scale

2. Google's Architecture: The Doorman Client-Side Quota Architecture

[ Google Service Client Fleet (50,000 Containers) ]
      โ”‚                   โ”‚                   โ”‚
      โ–ผ                   โ–ผ                   โ–ผ
 [ Local Bucket ]    [ Local Bucket ]    [ Local Bucket ]
 (Local Cache)       (Local Cache)       (Local Cache)
      โ”‚                   โ”‚                   โ”‚
      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                          โ”‚ (Periodic Token Leases: Every 5s)
                          โ–ผ
            [ Google Doorman Quota Server ]
              โ”œโ”€โ”€ Global Resource Capacity Model
              โ”œโ”€โ”€ Fair-Share Proportional Allocation
              โ””โ”€โ”€ Dynamic Master Election via Chubby

A. The Lease-Based Token Model

B. Fair-Share Allocation Algorithm


๐ŸŽฌ Deep Dive 2: How Netflix Uses Rate Limiting (Zuul Adaptive Concurrency Limits)

1. Production Context & Scale

2. Netflix's Architecture: TCP Vegas & Little's Law

[ Inbound Request Stream to Zuul Gateway ]
                    โ”‚
                    โ–ผ
[ Netflix Adaptive Concurrency Limiter (Netty Interceptor) ]
  โ”œโ”€โ”€ Measures Round-Trip Latency (RTT) per Request
  โ”œโ”€โ”€ Compares with Moving Baseline (No-Load RTT)
  โ”‚
  โ”œโ”€โ”€ If RTT <= Baseline: Limit = Limit + 1  (Additive Increase)
  โ””โ”€โ”€ If RTT > Baseline:  Limit = Limit * ฮฒ  (Multiplicative Decrease)
                    โ”‚
                    โ–ผ
[ Upstream Microservice Target Pool ]

A. Why Static RPS Limits Fail at Netflix

Concurrency = Throughput ร— Latency

B. Priority Shedding

When congestion occurs, Netflix sheds traffic according to strict priority tiers:

  1. Critical (Never Dropped): Video playback start, license checks.
  2. Interactive: UI catalog browsing, user search.
  3. Background (Dropped First): Telemetry pings, viewing history sync.

๐Ÿ›ก๏ธ Deep Dive 3: How Cloudflare Implements Line-Rate Drops (eBPF & XDP)

1. Production Context & Scale

2. In-Kernel eBPF & XDP Drops


๐Ÿ’ณ Deep Dive 4: How Stripe Uses Atomic Redis Sliding Windows

1. Production Context & Scale

2. Atomic Redis Lua Execution


โš–๏ธ Comparative Architecture Matrix

Architectural Dimension Google Doorman Netflix Concurrency Limits Cloudflare Edge Limiter Stripe API Limiter
Primary Level Client-Side / Quota Server Gateway / Interceptor L3/L4/L7 Kernel (eBPF) L7 Reverse Proxy
Limiting Strategy Lease-based Fair-Share Dynamic RTT Feedback (TCP Vegas) Volumetric Sliding Window Multi-Tier Token & Sliding Window
State Storage In-Memory Doorman Server Local In-Memory Counters eBPF Kernel Maps Distributed Redis Clusters
Drop Action Client delays or throttles Drops non-critical traffic XDP_DROP at line rate HTTP 429 Too Many Requests

๐ŸŽฏ System Design Interview Takeaways

  1. Never Propose a Single Global Limiter: Structure rate limiting as a multi-tier defense: Edge eBPF DDoS filter -> API Gateway Token Bucket -> Concurrency Limiter -> Database query cost limiter.
  2. Preventing Race Conditions: Always explain that distributed rate limiters in Redis require atomic Lua scripts or Redis Cell modules to avoid race conditions.
  3. Adaptive Concurrency vs Static Limits: Differentiate yourself by explaining why static RPS limits fail during cascading failures and proposing Adaptive Concurrency Limits (Little's Law).