Skip to content

Support retry delay with jitter? #509

@rileytomasek

Description

@rileytomasek

Thanks for creating ky! I used it extensively in my libraries and projects.

I'm running into an issue where I'm making a lot of calls in parallel to an API with a rate limit and the 429 retries are all happening at the same time and triggering the rate limit again. I've tested with a forked version of Ky and adding a random jitter to the retry time makes things much better.

I'm happy to contribute a PR, but wanted to see which, if any, solutions you are open to:

  1. Add a random jitter (and potentially a way to control it) to the retry calculation here
  2. Allow passing a custom function to replace BACKOFF_FACTOR * (2 ** (this._retryCount - 1)) * 1000
  3. Make it possible to do this from the beforeRetry hook?

For more context, what I tested was calculating a jitter factor like JITTER_FACTOR * randomBetween(1, -1) and then multiplying the existing retry time by that. It could be configured so that the default value is 1, so there is no change to existing retry time calculation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions