Aviary

Resilience

Composable resilience policies for NestJS — timeout, retry, circuit breaker and failover, with a pluggable distributed circuit-breaker store.

@dudousxd/nestjs-resilience is a NestJS-native resilience toolkit — composable timeout, retry, circuit breaker and failover policies, with a pluggable, distributed circuit-breaker store. Think cockatiel for NestJS, wired into the ecosystem's conventions (diagnostics, context, event-emitter).

Alpha

Published as alpha at 0.2.0. The API here matches the current source. Pin a version in production.

Compose policies, outer to inner

Each policy is a small object with an execute(fn) method. wrap() composes them — the first argument is the outermost layer, the last is closest to your operation:

import { wrap, timeout, retry, exponential, circuitBreaker, InMemoryResilienceStore } from '@dudousxd/nestjs-resilience';

const store = new InMemoryResilienceStore();

const policy = wrap(
  timeout(2_000),
  retry({ attempts: 3, backoff: exponential(100) }),
  circuitBreaker({ key: 'payments', store, threshold: 5, cooldownMs: 30_000 }),
);

await policy.execute(() => chargeCard(order)); // timeout → retry → breaker → chargeCard

Three ways to use it

Wired into the ecosystem

State transitions (circuit opened/closed/half-open, short-circuited, failover) emit over @dudousxd/nestjs-diagnostics on the aviary:resilience:* channel — so Telescope or any subscriber can observe them. An optional @nestjs/event-emitter mirror lets you react in-app, and @dudousxd/nestjs-context makes breaker keys tenant-aware automatically. See Integrations.

Install

pnpm add @dudousxd/nestjs-resilience

@nestjs/common and @nestjs/core are peer dependencies; @dudousxd/nestjs-diagnostics is an optional, soft-detected one. Head to Getting Started.

On this page