Lesson 20 / 32
Rate Limiting Algorithms, Deep Dive
Token bucket vs leaky bucket vs sliding window, compared.
Leaky bucket
A leaky bucket models requests as water poured into a bucket with a fixed hole at the bottom: it processes (leaks) at a constant rate regardless of burst size, queuing or dropping the rest. It smooths traffic; token bucket instead allows bursts up to the cap.
Sliding window
A fixed window (e.g. 'max 100 req per minute, reset at :00') lets a client burst 100 at 11:59:59 and another 100 at 12:00:01 — 200 in 2 seconds. A sliding window log or counter weighs recent sub-windows to smooth this edge effect.
Quick check: Which algorithm enforces a strictly constant output rate, smoothing out bursts entirely?
- Token bucket
- Leaky bucket
- Fixed window counter
Answer
Leaky bucket — Leaky bucket processes at a fixed rate no matter how bursty the input is, unlike token bucket which allows saved-up bursts through.