Rate Limiter Cheat Sheet
Key concepts, trade-offs, and quick-reference notes for your interview prep.
Token Bucket vs Sliding Window
#1💡 AWS API Gateway and Stripe chose token bucket. Cloudflare chose sliding window for DDoS protection. Name these in the interview to show awareness.
Redis INCR + EXPIRE Atomic Pair
#2Memory: Fixed Window Counter
#3💡 Fixed window is the cheapest algorithm by memory. We chose sliding window counter instead because the boundary burst problem is unacceptable for our use case.
Sliding Window Counter Saves 86% Memory
#4💡 Sliding window counter is the sweet spot: nearly as accurate as sliding log at a fraction of the memory. Name the 86% savings in the interview.
HTTP 429 + Retry-After Header
#5X-RateLimit Headers
#6💡 GitHub, Twitter, and Stripe all return these three headers. They are not in any RFC but are a de facto standard.
Lua Script for Atomicity
#7💡 EVALSHA caches the script server-side. We send the SHA (not the full script) on every request to save bandwidth.
Fail-Open vs Fail-Closed
#8Per-API vs Per-User vs Per-IP
#9💡 Layer all three: per-IP at the load balancer, per-user at the gateway, per-API at the service level.
Local + Global Two-Tier Limiting
#10💡 The two-tier approach trades precision for latency. Acceptable when the limit is advisory, not a hard security boundary.