@@ -19,8 +19,8 @@ time, but you can use them for your own features too.
19
19
Rate Limiting Strategies
20
20
------------------------
21
21
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 **.
24
24
25
25
Fixed Window Rate Limiter
26
26
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -35,6 +35,22 @@ could make the 4,999 requests in the last minute of some hour and another 5,000
35
35
requests during the first minute of the next hour, making 9,999 requests in
36
36
total in two minutes and possibly overloading the server.
37
37
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
+
38
54
Token Bucket Rate Limiter
39
55
~~~~~~~~~~~~~~~~~~~~~~~~~
40
56
0 commit comments