novu-java icon indicating copy to clipboard operation
novu-java copied to clipboard

Add Exponential Retry Mechanism with Idempotency Headers

Open Cliftonz opened this issue 2 years ago • 8 comments

In order to enhance the resilience and reliability of our SDK, we would like to introduce an Exponential Retry mechanism for retrying failed requests. Additionally, to ensure the idempotent processing of requests, it's vital to incorporate support for providing an Idempotency Key as per the draft specified in the HTTP Idempotency Key Header Field.

The key requirements for this implementation include:

  1. Exponential Retry Mechanism:

    • The SDK should retry failed requests following an exponential backoff strategy to minimize the contention and impact on the systems involved.
    • The SDK should ensure that the retry mechanism is configurable (e.g., max retries, initial delay, maximum delay).
  2. Idempotency Key Provisioning:

    • The SDK should allow for either automatic or manual provisioning of an Idempotency Key for each request.
    • The Idempotency Key should conform to either CUID, ULID, or UUID formats as specified in the draft.
    • The Idempotency Key should be included in the HTTP Header as Idempotency-Key and following the standards outlined in the draft.
  3. Configuration and Documentation:

    • The SDK should provide configuration options for enabling/disabling the Exponential Retry mechanism and Idempotency Key provisioning.
    • Comprehensive documentation should be provided explaining the configuration options, operational behavior, and the benefits of using the Exponential Retry mechanism along with Idempotency Keys.

Acceptance Criteria:

  • [ ] Implementation of the Exponential Retry mechanism with configurable parameters.
  • [ ] Provisioning of Idempotency Keys, either automatically or manually, conforming to specified formats (CUID, ULID, or UUID).
  • [ ] Adequate unit and integration testing to ensure the robustness and reliability of the implemented features.
  • [ ] Comprehensive documentation on the usage and configuration of the Exponential Retry mechanism and Idempotency Key provisioning.
  • [ ] Adherence to the specifications outlined in the HTTP Idempotency Key Header Field draft.

Update: You can reference the go-lang library to keep the method signature and configuration the same. https://github.com/novuhq/go-novu/pull/62

Please refer to the draft for further details on the HTTP Idempotency Key Header Field and ensure adherence to the specified standards while implementing this feature in the SDK.

Cliftonz avatar Oct 06 '23 19:10 Cliftonz

Hi, please assign this to me.

Also I had below doubts:

  • Will this issue be broken down to smaller issue as we have different apis. (just like we did for refactoring of APIs)
  • Will ask more doubts in discord as I progress on this issue.

git-ashug avatar Oct 13 '23 18:10 git-ashug

@git-ashug Hi no as this effects the underlying http request mechanism which is all one issue. You can see an example how we do this in the go sdk.

Feel free to ask any questions you need to implement this.

Cliftonz avatar Oct 14 '23 23:10 Cliftonz

@git-ashug are you still working on this? @Cliftonz Can I work on this?

charan2628 avatar Dec 17 '23 05:12 charan2628

Hello @charan2628 , I have raised a draft PR and asked some questions there to maintainers. If they don't respond, you can take it from here. Also, would be a great help if you too review the PR and let me know what to do next. Thanks!

git-ashug avatar Dec 17 '23 05:12 git-ashug

@git-ashug In RetryInterceptor response is null in the while condition for starting iteration

charan2628 avatar Dec 17 '23 10:12 charan2628

Hi @charan2628 , you can take this task up.

git-ashug avatar Dec 31 '23 15:12 git-ashug

Thank you @git-ashug

charan2628 avatar Jan 02 '24 16:01 charan2628