@@ -19,8 +19,8 @@ time, but you can use them for your own features too.
1919Rate 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
2525Fixed 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
3535requests during the first minute of the next hour, making 9,999 requests in
3636total 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+
3854Token Bucket Rate Limiter
3955~~~~~~~~~~~~~~~~~~~~~~~~~
4056
0 commit comments