fiber icon indicating copy to clipboard operation
fiber copied to clipboard

🚀 v3 Request: Retry Mechanism

Open gozeloglu opened this issue 2 years ago • 5 comments

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

gozeloglu avatar Mar 30 '22 09:03 gozeloglu

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

welcome[bot] avatar Mar 30 '22 09:03 welcome[bot]

Can I contribute to this issue? Thanks! @ReneWerner87

vishjain avatar Jul 08 '22 00:07 vishjain

Sure

ReneWerner87 avatar Jul 08 '22 05:07 ReneWerner87

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.

gozeloglu avatar Jul 08 '22 06:07 gozeloglu

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

ReneWerner87 avatar Jul 08 '22 06:07 ReneWerner87