npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-retry-system

v2.0.1

Published

A lightweight and production-ready resilience library for Node.js providing Exponential Backoff retry strategy and Circuit Breaker pattern to handle API failures, network instability, and microservice reliability with automatic retries, failure protection

Readme

Nodejs Advanced Retry System

A lightweight and resilient retry library for Node.js featuring:

  • Exponential Backoff
  • Optional Jitter
  • Circuit Breaker Pattern
  • Retry Metrics
  • Custom Retry Errors
  • Promise-based API
  • Production-ready fault tolerance

Perfect for:

  • API requests
  • Database operations
  • External service calls
  • Network retry strategies
  • Preventing cascading failures

Installation

npm install node-retry-system

Features

✅ Exponential backoff retry strategy
✅ Optional jitter support
✅ Circuit breaker protection
✅ Custom retry error handling
✅ Promise-based execution
✅ Lightweight and dependency-free


Quick Start

Basic Retry

const {
  RetrySystem
} = require("node-retry-system");

const retry = new RetrySystem({
  retry: {
    delay: 1000,
    maxRetries: 3,
    jitter: true
  },
  circuitBreaker: {
    failureThreshold: 5,
    restTimeout: 10000
  }
});

async function fetchData() {
  return "Success";
}

(async () => {
  try {
    const result = await retry.execute(fetchData);
    console.log(result);
  } catch (err) {
    console.error(err);
  }
})();

Retry Example

Simulating an unstable API.

const {
  RetrySystem
} = require("node-retry-system");

const retry = new RetrySystem({
  retry: {
    delay: 1000,
    maxRetries: 5,
    jitter: true
  }
});

async function fakeApiCall() {
  return new Promise((resolve, reject) => {
    const success = Math.random() > 0.5;

    setTimeout(() => {
      if (success) {
        resolve({
          status: 200,
          message: "API request successful"
        });
      } else {
        reject({
          status: 500,
          message: "Server error"
        });
      }
    }, 500);
  });
}

(async () => {
  try {
    const response = await retry.execute(
      async () => await fakeApiCall()
    );

    console.log(response);
  } catch (err) {
    console.error(err);
  }
})();

API Reference


RetrySystem

Combines:

  • Exponential Backoff
  • Circuit Breaker
  • Retry Error Handling

Constructor

new RetrySystem(options)

Options

| Property | Type | Description | |---|---|---| | retry | Object | Retry strategy configuration | | circuitBreaker | Object | Circuit breaker configuration |

Execute

await retry.execute(fn)

| Param | Type | Description | |---|---|---| | fn | Function | Async function to execute |

Returns:

Promise<T>

Throws:

RetryError

ExponentialBackoff

Retry strategy using exponentially increasing delays.

Constructor

new ExponentialBackoff(options)

Options

| Property | Type | Default | Description | |---|---|---|---| | delay | number | 1000 | Base retry delay (ms) | | maxRetries | number | 3 | Maximum retry attempts | | jitter | boolean | false | Randomized delay |

Delay Formula

Without jitter:

delay × (2 ^ attempt)

With jitter:

random(0, delay × 2 ^ attempt)

CircuitBreaker

Protects failing services from repeated execution.

States

| State | Description | |---|---| | CLOSED | Requests flow normally | | OPEN | Requests blocked | | HALF_OPEN | Trial execution allowed |

Constructor

new CircuitBreaker(options)

Options

| Property | Type | Default | Description | |---|---|---|---| | failureThreshold | number | 5 | Failures before OPEN | | restTimeout | number | 10000 | Recovery timeout |


RetryError

Custom error containing retry execution details.

Example:

try {
  await retry.execute(fn);
} catch (err) {
  console.log(err.message);
  console.log(err.attempts);
  console.log(err.duration);
}

How It Works

Execution flow:

Request
   │
   ▼
Circuit Breaker
   │
   ▼
Exponential Backoff Retry
   │
   ▼
Success / RetryError

Retry Lifecycle

Attempt 1 → Fail
      ↓
Wait (Backoff)
      ↓
Attempt 2 → Fail
      ↓
Wait (Backoff)
      ↓
Attempt 3 → Success

Circuit breaker lifecycle:

CLOSED
   ↓
Failures exceed threshold
   ↓
OPEN
   ↓
Timeout expires
   ↓
HALF_OPEN
   ↓
Success → CLOSED
Failure → OPEN

Error Handling

Example:

try {
  await retry.execute(fetchUsers);
} catch (err) {
  console.error(
    "Operation failed after retries",
    err
  );
}

Use Cases

This package is useful for:

  • REST API retry handling
  • Payment gateway requests
  • Database reconnection logic
  • Third-party service integrations
  • Microservice communication
  • Network fault tolerance

Development

Clone repository:

git clone [https://github.com/Dipaque/nodejs-retry-system](https://github.com/Dipaque/nodejs-retry-system)

Install dependencies:

npm install

Run tests:

npm test

License

MIT License.


Contributing

Contributions, issues, and feature requests are welcome.

Feel free to open a pull request or create an issue.


Author

Deepak R

GitHub: Deepak R