Skip to content

DX-1817: Add tips about window behavior #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions redis/sdks/ratelimit-py/algorithms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ window is 10 seconds long. When a new request comes in, the current time is used
to determine the window and a counter is increased. If the counter is larger
than the set limit, the request is rejected.

<Tip>
In fixed & sliding window algorithms, the reset time is based on fixed time boundaries (which depend on the period), not on when the first request was made. So two requests made right before the window ends still count toward the current window, and limits reset at the start of the next window.
</Tip>

### Pros

- Very cheap in terms of data size and computation
Expand Down Expand Up @@ -73,6 +77,12 @@ ratelimit = Ratelimit(
)
```

<Tip>
`reset` field in the [`limit`](/redis/sdks/ratelimit-py/gettingstarted) method of sliding window does not
provide an exact reset time. Instead, the reset time is the start time of
the next window.
</Tip>

## Token Bucket

Consider a bucket filled with maximum number of tokens that refills constantly
Expand Down
10 changes: 10 additions & 0 deletions redis/sdks/ratelimit-ts/algorithms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ window is 10 seconds long. When a new request comes in, the current time is used
to determine the window and a counter is increased. If the counter is larger
than the set limit, the request is rejected.

<Tip>
In fixed & sliding window algorithms, the reset time is based on fixed time boundaries (which depend on the period), not on when the first request was made. So two requests made right before the window ends still count toward the current window, and limits reset at the start of the next window.
</Tip>

### Pros

- Very cheap in terms of data size and computation
Expand Down Expand Up @@ -116,6 +120,12 @@ Create a new ratelimiter, that allows 10 requests per 10 seconds.
</Tab>
</Tabs>

<Tip>
`reset` field in the [`limit`](/redis/sdks/ratelimit-ts/methods#limit) and [`getRemaining`](/redis/sdks/ratelimit-ts/methods#getremaining) methods of sliding window do not
provide an exact reset time. Instead, the reset time is the start time of
the next window.
</Tip>

## Token Bucket

Consider a bucket filled with `{maxTokens}` tokens that refills constantly at
Expand Down