Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry on ratelimit status #217

Closed
wants to merge 5 commits into from
Closed

Retry on ratelimit status #217

wants to merge 5 commits into from

Conversation

CahidArda
Copy link
Contributor

With this PR, we update the qstash-js client to retry ratelimit errors. The client will retry with this algorithm by default

((lastBackoff) => Math.max(lastBackoff, Math.random() * 4000) + 1000),

In a nutshell, it's the max of last backoff + 1s and 1-5s. The aim is to spread the load over time while keeping the durations small.

Copy link

linear bot commented Dec 2, 2024

src/client/http.ts Outdated Show resolved Hide resolved
@@ -75,6 +76,19 @@ export type RetryConfig =
* ```
*/
backoff?: (retryCount: number) => number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the comments, I couldn't understand the usecase for the normal backoff. I know ratelimit is applied for 429, but what is this for? Maybe we can explain a bit more in the docstring

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's for when fetch throws an error, instead of returning a response with some status (200 or non-200)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok, after reading the code I understood, a little note in the comments would be very helpfull

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated docs 👍

@CahidArda
Copy link
Contributor Author

decided to close this PR and update the default retry duration to be 1 sec in the second retry

@CahidArda CahidArda closed this Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants