DEV Community

Avinash
Avinash

Posted on

flowshield: TypeScript Resilience Library (Circuit Breaker, Retry, Timeout) for Edge Runtimes

Why Resilience Matters in Production

Every distributed system fails eventually. APIs time out, databases get overloaded, third-party services go down. Without resilience patterns, one failing dependency can cascade into a full system outage.

flowshield is a zero-dependency TypeScript-first resilience library that gives you composable fault-tolerance policies for any async operation.

What's Inside

Retry with Exponential Backoff

import { retry } from 'flowshield';

const result = await retry(
  () => fetchFromAPI(),
  { attempts: 3, backoff: 'exponential', baseDelay: 100 }
);
Enter fullscreen mode Exit fullscreen mode

Circuit Breaker

Automatically stops calling a failing service and recovers when it's healthy:

import { circuitBreaker } from 'flowshield';

const breaker = circuitBreaker({
  threshold: 5,        // open after 5 failures
  timeout: 30_000,     // try again after 30s
  halfOpenRequests: 2  // test with 2 requests
});

const result = await breaker.execute(() => callExternalService());
Enter fullscreen mode Exit fullscreen mode

Timeout

import { timeout } from 'flowshield';

const result = await timeout(
  () => slowOperation(),
  { ms: 3000 } // cancel if takes more than 3s
);
Enter fullscreen mode Exit fullscreen mode

Composable Policies

import { wrap, retry, circuitBreaker, timeout, fallback } from 'flowshield';

const resilientFetch = wrap(
  retry({ attempts: 3 }),
  circuitBreaker({ threshold: 5 }),
  timeout({ ms: 3000 }),
  fallback({ value: cachedData })
);

const data = await resilientFetch(() => fetchData());
Enter fullscreen mode Exit fullscreen mode

Other Policies

  • Hedge — race multiple attempts, take the fastest response
  • Cache — built-in memoization with TTL
  • Bulkhead — limit concurrency to protect downstream

Works Everywhere

Tree-shakeable, dual ESM/CJS, zero dependencies. Runs on Node.js, Bun, Deno, and Cloudflare Workers.

npm install flowshield
bun add flowshield
Enter fullscreen mode Exit fullscreen mode

GitHub: https://github.com/Avinashvelu03/flowshield

What resilience patterns do you use in production? Would love to hear your thoughts!

Top comments (0)