Choosing the Right Rate Limiting Algorithm
Compare the core rate limiting algorithms — fixed window, sliding window, token bucket, and leaky bucket — and learn when each fits your traffic profile and fairness goals.
Why the Algorithm Matters
A rate limit policy is only as good as the algorithm that enforces it. The same limit of 100 requests/minute behaves very differently depending on how you count.
In this lesson we compare four classic approaches and learn how to pick one based on your fairness, burst, and accuracy needs.
Fixed Window Counter
The simplest approach: count requests in a fixed time window (for example each calendar minute) and reset the counter at the boundary.
- Pros: trivial to implement, low memory
- Cons: allows a burst of
2xthe limit around the window edge
def allow(counter, limit):
if counter['count'] >= limit:
return False
counter['count'] += 1
return TrueAll lessons in this course
- Throttling vs. Rate Limiting Explained
- Bursting and Grace Period Policies
- Client-Side vs. Server-Side Limits
- Choosing the Right Rate Limiting Algorithm