Member-only story
[System Design] Rate Limiting Algorithms
Read full article for free if you don’t have medium membership: https://liverungrow.medium.com/system-design-rate-limiting-algorithms-8a26892fb97f?sk=a3a37f345e80fd2503ba5b494f105cec
Fixed Window
A simple counter that resets every window
(e.g. every 60 seconds).
If the limit is 4 requests per minute:
- Client can send up to 4 requests between 00:00 and 00:59.
- At 01:00, the counter resets to zero.
❌ ‘Burst at boundary’ does not handle bursts of traffic efficiently. Users can send a huge burst of request at the end of the first window, and the beginning of the second window. (A client could send 4 requests at 00:59, and another 4 at 01:00.) This could potentially overload the server.
Sliding Window
The sliding window algorithm is used to limit the number of requests a client can make over a specific period. It’s more flexible than a fixed window, and smoother than token bucket in many cases.
You define a rate limit, like 100 requests per 60 seconds.