SteelReed

Search

Search posts, questions…

Caching & RedisQuestion 18 / 24

Middle

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.

allow short burstssteady output rateaccurate and cheapsimplest possibleWhat about bursts?Token bucketLeaky bucketSliding window counterFixed window,double at boundary

3 points to say:

  1. Fixed window breaks at the boundary: 100 req at 00:59 and 100 at 01:00 is 200 requests in 2 seconds, all allowed.
  2. Sliding window counter needs only two counters and approximates well; sliding log is exact but memory grows with the request count.
  3. 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.