fiber
fiber copied to clipboard
🚀 v3 Request: Retry Mechanism
Is your feature request related to a problem?
Describe the solution you'd like
I am planning to add the exponential backoff algorithm. It is a widely used retry policy. Basically, there will be 2 different functions. One is Retry()
(or Do()
) method and NextBackoff()
(or NextTime()
) methods. Of course, there will be some helper methods like NewBackoff()
, Reset()
. This feature will be flexible. The users can be used Retry()
method and everything will be handled by the package. They won't consider details. They will just call the method like this:
backoff.Retry(func() error{
// Do whatever you want
return err
})
Or, maybe some users want to handle the retry part themselves. In this case, we provide all functionalities other than Retry()
method like Reset()
, NextTime()
, Sleep()
. They use the package and call the methods like this:
for i := 0; i < n; i++ {
...
next := backoff.NextTime()
backoff.Sleep(next)
}
...
backoff.Reset()
Also, we can add two options to check the retry count/time with Context
and retryCount
. In Context
usage, we set timeout to context
and retry goes until timeout expires. For retryCount
usage, we set number of retry step like 10, and the method retries 10 times.
Describe alternatives you've considered Regular Interval: Waits in regular period of time. Incremental Intervals: Waiting time is increasing incrementally. Additional context
- cenkalti/backoff
- https://aws.amazon.com/builders-library/timeouts-retries-and-backoff-with-jitter/
- https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
- https://docs.microsoft.com/en-us/azure/architecture/best-practices/transient-faults
- Other Go packages
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord
Can I contribute to this issue? Thanks! @ReneWerner87
Sure
I was expecting to implement this. I mentioned that wanted to implemenet it in discussion section and proposed above solutions. As I remember @ReneWerner87 told me that v3 implementations hasn't been started yet when I asked it.
there is the https://github.com/gofiber/fiber/tree/v3-beta branch you can fork another branch from it and create a pull request for it on the beta branch
Sorry @vishjain gozeloglu has the prerogative and if he has time and desire he should start with it