https://github.com/cenkalti/backoff
⏱ The exponential backoff algorithm in Go
https://github.com/cenkalti/backoff
golang
Last synced: 11 months ago
JSON representation
⏱ The exponential backoff algorithm in Go
- Host: GitHub
- URL: https://github.com/cenkalti/backoff
- Owner: cenkalti
- License: mit
- Created: 2014-02-26T00:00:16.000Z (over 12 years ago)
- Default Branch: v5
- Last Pushed: 2025-02-27T12:53:06.000Z (over 1 year ago)
- Last Synced: 2025-05-13T14:06:45.568Z (about 1 year ago)
- Topics: golang
- Language: Go
- Homepage:
- Size: 137 KB
- Stars: 3,669
- Watchers: 28
- Forks: 194
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- go-awesome - backoff - 指数退避算法(Exponential Backoff) (开源类库 / 算法)
- go-awesome - Backoff - Exponential backoff (Open source library / Algorithm)
- awesome-ccamel - cenkalti/backoff - ⏱ The exponential backoff algorithm in Go (Go)
README
# Exponential Backoff [![GoDoc][godoc image]][godoc]
This is a Go port of the exponential backoff algorithm from [Google's HTTP Client Library for Java][google-http-java-client].
[Exponential backoff][exponential backoff wiki]
is an algorithm that uses feedback to multiplicatively decrease the rate of some process,
in order to gradually find an acceptable rate.
The retries exponentially increase and stop increasing when a certain threshold is met.
## Usage
Import path is `github.com/cenkalti/backoff/v5`. Please note the version part at the end.
For most cases, use `Retry` function. See [example_test.go][example] for an example.
If you have specific needs, copy `Retry` function (from [retry.go][retry-src]) into your code and modify it as needed.
## Contributing
* I would like to keep this library as small as possible.
* Please don't send a PR without opening an issue and discussing it first.
* If proposed change is not a common use case, I will probably not accept it.
[godoc]: https://pkg.go.dev/github.com/cenkalti/backoff/v5
[godoc image]: https://godoc.org/github.com/cenkalti/backoff?status.png
[google-http-java-client]: https://github.com/google/google-http-java-client/blob/da1aa993e90285ec18579f1553339b00e19b3ab5/google-http-client/src/main/java/com/google/api/client/util/ExponentialBackOff.java
[exponential backoff wiki]: http://en.wikipedia.org/wiki/Exponential_backoff
[retry-src]: https://github.com/cenkalti/backoff/blob/v5/retry.go
[example]: https://github.com/cenkalti/backoff/blob/v5/example_test.go