Skip to the content.

πŸ”Ή 1. Token Bucket


πŸ”Ή 2. Leaky Bucket


πŸ”Ή 3. Fixed Window Counter


πŸ”Ή 4. Sliding Window Log


πŸ”Ή 5. Sliding Window Counter


βœ… Summary:


Here’s a comparison table for quick revision of rate limiting algorithms:


Algorithm Pros βœ… Cons ❌ Typical Use Cases πŸ“Œ
Token Bucket - Allows bursts
- Enforces average rate
- Efficient (just counters)
- Bursts can overwhelm downstream if too big API rate limiting where short bursts are okay (e.g., user actions, microservices)
Leaky Bucket - Smooth, constant output rate
- Simple implementation
- Doesn’t allow bursts
- Can delay legitimate requests
Network traffic shaping, preventing sudden spikes
Fixed Window Counter - Very simple
- Low memory usage
- Unfair at boundaries (burst at window edges)
- Can exceed rate briefly
Basic API rate limiting (small apps, quick checks)
Sliding Window Log - Very accurate
- No burst unfairness
- High memory (stores all request timestamps)
- Slower at scale
High-security APIs, login attempt throttling
Sliding Window Counter - More fair than fixed window
- Efficient (just two counters)
- Good balance
- Slightly more complex
- Approximate, not exact
Large-scale API gateways (e.g., NGINX, Envoy, AWS API Gateway)

πŸ‘‰ Shortcut to remember: