How do the rate limiting algorithms fixed window, sliding window, token bucket and leaky bucket differ?
Short answer
The four algorithms differ in how they treat bursts: fixed window is simple but allows double the limit at the boundary, sliding window smooths the boundary, token bucket allows bursts up to the bucket capacity, leaky bucket drains at a fixed rate.
3 points to say:
- Fixed window breaks at the boundary: 100 req at 00:59 and 100 at 01:00 is 200 requests in 2 seconds, all allowed.
- Sliding window counter needs only two counters and approximates well; sliding log is exact but memory grows with the request count.
- Token bucket allows bursts and needs no timer (Guava, Bucket4j); use leaky bucket when the backend needs a steady flow.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.