Rate Limiting
Difficulty: Medium | Topic #15
What to Learn
Token bucket, leaky bucket, and sliding window algorithms; distributed rate limiting with Redis (atomic Lua scripts), rate limiting at the API gateway vs per-service, handling burst traffic.
Resources
- Hello Interview: Rate Limiter Breakdown ↗
- ByteByteGo: Rate Limiting Fundamentals ↗
- Gaurav Sen: Token Bucket, Leaky Bucket, Sliding Logs ↗
Covered by Problems
| Problem | Difficulty | Link |
|---|---|---|
| URL Shortener/Bitly | Easy | → |
| Rate Limiter | Medium | → |
| LLM Service (ChatGPT) | Hard | → |
Key Concepts to Master
- Token bucket (allows bursts up to capacity) vs leaky bucket (constant output rate)
- Sliding window log vs sliding window counter tradeoffs
- Redis INCR + TTL for distributed counters
- Lua scripts for atomicity in Redis
- Rate limiting at the edge (API gateway) vs per-microservice