Skip to content

Commit 556f3cc

Browse files
committed
minor #14418 [RateLimiter] Adding docs for rate limit sliding window (Nyholm)
This PR was merged into the 5.x branch. Discussion ---------- [RateLimiter] Adding docs for rate limit sliding window Does this makes sense? Do we understand how it works? This will fix #14417 Commits ------- 2380052 Adding docs for rate limit sliding window
2 parents a7e12d1 + 2380052 commit 556f3cc

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

rate_limiter.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ time, but you can use them for your own features too.
1919
Rate Limiting Strategies
2020
------------------------
2121

22-
Symfony's rate limiter implements two of the most common strategies to enforce
23-
rate limits: **fixed window** and **token bucket**.
22+
Symfony's rate limiter implements some of the most common strategies to enforce
23+
rate limits: **fixed window**, **sliding window** and **token bucket**.
2424

2525
Fixed Window Rate Limiter
2626
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -35,6 +35,22 @@ could make the 4,999 requests in the last minute of some hour and another 5,000
3535
requests during the first minute of the next hour, making 9,999 requests in
3636
total in two minutes and possibly overloading the server.
3737

38+
Sliding Window Rate Limiter
39+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
40+
41+
The sliding window algorithm is gracefully handling the drawback from the fixed
42+
window algorithm. To reduce bursts requests the rate limit is calculated based on
43+
the current window and the previous window.
44+
45+
For example: The limit is 5,000 requests per hour. If a user made 4,000 requests
46+
the previous hour and 500 requests this hour. 15 minutes in to the current hour
47+
(25% of the window) the hit count would be calculated as: 75% * 4,000 + 500 = 3,500.
48+
At this point in time the user can only do 1,500 more requests.
49+
50+
The math shows that the closer the last window is, the more will the hit count
51+
of the last window effect the current limit. This will make sure that a user can
52+
do 5.000 requests per hour but only if they are spread out evenly.
53+
3854
Token Bucket Rate Limiter
3955
~~~~~~~~~~~~~~~~~~~~~~~~~
4056

0 commit comments

Comments
 (0)