https://github.com/russellluo/slidingwindow
Golang implementation of Sliding Window Algorithm for distributed rate limiting.
https://github.com/russellluo/slidingwindow
golang rate-limiting
Last synced: over 1 year ago
JSON representation
Golang implementation of Sliding Window Algorithm for distributed rate limiting.
- Host: GitHub
- URL: https://github.com/russellluo/slidingwindow
- Owner: RussellLuo
- License: mit
- Created: 2019-11-24T12:01:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-24T13:19:06.000Z (about 2 years ago)
- Last Synced: 2025-03-28T11:11:40.379Z (over 1 year ago)
- Topics: golang, rate-limiting
- Language: Go
- Homepage:
- Size: 499 KB
- Stars: 394
- Watchers: 9
- Forks: 38
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slidingwindow
Golang implementation of Sliding Window Algorithm for distributed rate limiting.
## Installation
```bash
$ go get -u github.com/RussellLuo/slidingwindow
```
## Design
`slidingwindow` is an implementation of the scalable rate limiting algorithm used by [Kong][1].
Suppose we have a limiter that permits 100 events per minute, and now the time comes at the "75s" point, then the internal windows will be as below:

In this situation, the limiter has permitted 12 events during the current window, which started 15 seconds ago, and 86 events during the entire previous window. Then the count approximation during the sliding window can be calculated like this:
```
count = 86 * ((60-15)/60) + 12
= 86 * 0.75 + 12
= 76.5 events
```
## Test Utility

For details, see [testutil](testutil).
## Documentation
For usage and examples see the [Godoc][2].
## License
[MIT][3]
[1]: https://konghq.com/blog/how-to-design-a-scalable-rate-limiting-algorithm/
[2]: https://godoc.org/github.com/RussellLuo/slidingwindow
[3]: http://opensource.org/licenses/MIT