async-retry vs backoff vs promise-retry vs retry vs retry-axios vs retry-request
JavaScript Retry Libraries
async-retrybackoffpromise-retryretryretry-axiosretry-requestSimilar Packages:

JavaScript Retry Libraries

Retry libraries in JavaScript provide mechanisms to automatically retry failed asynchronous operations, such as API calls or database queries, to enhance reliability and resilience in applications. These libraries help manage transient errors by implementing various retry strategies, allowing developers to configure parameters like the number of retries, delay between attempts, and conditions for retrying. This is particularly useful in scenarios where network issues or temporary service outages may occur, ensuring that applications can gracefully handle failures without crashing or requiring manual intervention.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
async-retry01,909-305 years agoMIT
backoff0336-1110 years agoMIT
promise-retry0318-116 years agoMIT
retry01,260-205 years agoMIT
retry-axios050557.8 kB25 months agoApache-2.0
retry-request06916.1 kB38 months agoMIT

Feature Comparison: async-retry vs backoff vs promise-retry vs retry vs retry-axios vs retry-request

Retry Strategy

  • async-retry:

    async-retry allows for custom retry strategies, including exponential backoff and fixed delays. You can specify how long to wait between retries and how many attempts to make before failing.

  • backoff:

    backoff provides built-in support for exponential backoff strategies, allowing you to define the initial delay and the factor by which the delay increases with each retry, making it ideal for handling rate limits.

  • promise-retry:

    promise-retry offers a simple retry strategy that can be customized with a delay function, allowing you to control the timing of retries based on the error type or other conditions.

  • retry:

    retry supports both fixed and exponential backoff strategies, giving you the flexibility to define how retries are handled based on your application's needs.

  • retry-axios:

    retry-axios allows you to configure retry strategies directly in your Axios requests, including setting retry limits and delays, making it easy to manage HTTP request failures.

  • retry-request:

    retry-request provides a straightforward retry mechanism for HTTP requests, allowing you to specify the number of retries and the delay between attempts, suitable for simple use cases.

Integration

  • async-retry:

    async-retry is designed to work independently and can be integrated into any promise-based workflow, providing flexibility in various environments.

  • backoff:

    backoff is a standalone library that can be used with any asynchronous operation, making it versatile for different use cases beyond just HTTP requests.

  • promise-retry:

    promise-retry is specifically tailored for promises, ensuring seamless integration with promise-based APIs and workflows, making it easy to implement in modern JavaScript applications.

  • retry:

    retry can be used with both callbacks and promises, making it a versatile choice for applications that may use either approach for asynchronous operations.

  • retry-axios:

    retry-axios is specifically designed for use with Axios, providing a seamless integration that allows you to add retry logic directly to your HTTP requests without additional setup.

  • retry-request:

    retry-request is built to work with the request library, making it ideal for legacy applications that rely on this library for HTTP requests.

Configuration Options

  • async-retry:

    async-retry offers a wide range of configuration options, including the ability to customize the number of retries, delay between attempts, and conditions for retrying, providing great flexibility.

  • backoff:

    backoff allows for extensive configuration of backoff strategies, including setting maximum retry limits and customizing the backoff function, making it highly adaptable to specific requirements.

  • promise-retry:

    promise-retry provides straightforward configuration options, allowing you to specify the number of retries and a delay function, making it easy to set up and use.

  • retry:

    retry offers flexible configuration options for retry attempts, delays, and error handling, allowing you to tailor the retry logic to fit your needs.

  • retry-axios:

    retry-axios allows you to configure retry options directly in your Axios instance, including retry limits and conditions, making it convenient for developers familiar with Axios.

  • retry-request:

    retry-request provides basic configuration options for retry attempts and delays, making it easy to use without overwhelming complexity.

Error Handling

  • async-retry:

    async-retry allows you to specify error types that should trigger a retry, giving you control over which errors are retried and which are not, enhancing error handling capabilities.

  • backoff:

    backoff provides mechanisms to handle specific errors and can be configured to retry only on certain error types, making it useful for managing different failure scenarios.

  • promise-retry:

    promise-retry allows for custom error handling by enabling you to define conditions under which retries should occur, ensuring that only relevant errors trigger a retry.

  • retry:

    retry provides basic error handling capabilities, allowing you to specify which errors should be retried, but may require additional logic for more complex scenarios.

  • retry-axios:

    retry-axios integrates error handling directly into Axios, allowing you to specify which HTTP status codes should trigger a retry, making it easy to manage API errors.

  • retry-request:

    retry-request allows you to define which HTTP status codes should trigger a retry, providing a straightforward way to handle common HTTP errors.

Documentation and Community Support

  • async-retry:

    async-retry has comprehensive documentation and a growing community, making it easy to find examples and support for implementation.

  • backoff:

    backoff is well-documented with clear examples, and it has a supportive community that can assist with common use cases and issues.

  • promise-retry:

    promise-retry has straightforward documentation that covers the basics, making it easy for developers to get started quickly with examples and use cases.

  • retry:

    retry has decent documentation, but may lack some advanced examples; however, it is widely used, providing a level of community support through forums and GitHub.

  • retry-axios:

    retry-axios has good documentation that integrates with Axios documentation, making it easy for developers familiar with Axios to implement retry logic effectively.

  • retry-request:

    retry-request has basic documentation that covers its usage, but as the request library is deprecated, community support may be limited.

How to Choose: async-retry vs backoff vs promise-retry vs retry vs retry-axios vs retry-request

  • async-retry:

    Choose async-retry if you need a simple and flexible retry mechanism that supports both promises and async/await syntax. It allows for custom backoff strategies and is lightweight, making it suitable for most use cases.

  • backoff:

    Select backoff if you require advanced exponential backoff strategies with customizable delay and maximum retry limits. It is particularly useful for handling rate-limited APIs or services that enforce throttling.

  • promise-retry:

    Opt for promise-retry if you want a straightforward solution specifically designed for promises. It provides built-in support for retrying failed promises with customizable retry conditions and delays, making it easy to integrate into promise-based workflows.

  • retry:

    Use retry if you need a general-purpose retry library that works with both callbacks and promises. It offers a simple API and allows for flexible configuration of retry attempts and delays, suitable for various asynchronous operations.

  • retry-axios:

    Choose retry-axios if you are using Axios for HTTP requests and want to add retry functionality seamlessly. It integrates directly with Axios, allowing you to specify retry logic directly in your Axios configuration, making it ideal for RESTful API interactions.

  • retry-request:

    Select retry-request if you are working with the request library and need a retry mechanism for HTTP requests. It provides a straightforward way to add retry capabilities to your request calls, making it suitable for legacy applications that still use the request library.

README for async-retry

async-retry

Retrying made simple, easy, and async.

Usage

// Packages
const retry = require('async-retry');
const fetch = require('node-fetch');

await retry(
  async (bail) => {
    // if anything throws, we retry
    const res = await fetch('https://google.com');

    if (403 === res.status) {
      // don't retry upon 403
      bail(new Error('Unauthorized'));
      return;
    }

    const data = await res.text();
    return data.substr(0, 500);
  },
  {
    retries: 5,
  }
);

API

retry(retrier : Function, opts : Object) => Promise
  • The supplied function can be async or not. In other words, it can be a function that returns a Promise or a value.
  • The supplied function receives two parameters
    1. A Function you can invoke to abort the retrying (bail)
    2. A Number identifying the attempt. The absolute first attempt (before any retries) is 1.
  • The opts are passed to node-retry. Read its docs
    • retries: The maximum amount of times to retry the operation. Default is 10.
    • factor: The exponential factor to use. Default is 2.
    • minTimeout: The number of milliseconds before starting the first retry. Default is 1000.
    • maxTimeout: The maximum number of milliseconds between two retries. Default is Infinity.
    • randomize: Randomizes the timeouts by multiplying with a factor between 1 to 2. Default is true.
    • onRetry: an optional Function that is invoked after a new retry is performed. It's passed the Error that triggered it as a parameter.

Authors