32. Design a Rate Limiter as a Service
1
The interview prompt2
32.1 What do you ask first?3
32.2 How big is this, really?4
32.3 What are the doors?5
32.4 What do we store?6
32.5 What does the whole system look like?7
32.6 How do you pick the algorithm?8
32.7 How do counters work in Redis?9
32.8 What race conditions do you have to handle?10
32.9 How do limits work across regions?11
32.10 What would you say in the last five minutes?12
Score yourself13
Variations to practise14
Sources15
Code lab32. Design a Rate Limiter as a Service
Sources
3 min read+10 XP
Source notes
- Redis scripting: Lua scripts run atomically;
EVALSHA,TIME, hash tags and cluster slots: Redis documentation ("Scripting with Lua", "Redis Cluster specification"). - Algorithms and headers: see Chapter 25 and its source notes (Cloudflare sliding-window analysis, GitHub limits, RFC 6585, Retry-After).
- Token-bucket rate limiters in a production API: Stripe engineering blog, "Scaling your API with rate limiters" (2017).
- All traffic numbers, shard capacities and region demands are interview assumptions agreed in Step 1, not figures for any real service. Arithmetic computed 2026-10-08.
- Atomic script, race and multi-rule demos, and region rebalancing: tested 2026-10-08 (
code/ch32_rate_limiter_service.py, all checks pass).