Rate Limiting Comparison
Rate Limiting Comparison
Fixed Window Algorithm: This algorithm divides time into discrete, non-
overlapping intervals, such as seconds or minutes, and counts the number of
requests within each interval. If the count exceeds a predefined limit, further
requests are denied until the next interval begins. For example, with a limit of 5
requests per second, the algorithm resets the count at the start of each second,
allowing up to 5 requests in that second.
Token Bucket Algorithm: This algorithm uses a metaphorical bucket that holds
tokens, where each token represents permission to make a request. Tokens are
added to the bucket at a constant rate (refill rate, RRR), up to a maximum capacity
(CCC). Each request consumes one token, and if no tokens are available, the request
is denied. This allows for bursts up to CCC requests if the bucket is full, while
enforcing an average rate of RRR requests per second over time.