{"id":46852,"library":"zenvark","title":"Zenvark","description":"A distributed circuit breaker coordinated via Redis for high-availability applications. Current stable version is 1.2.0, released as an npm package with TypeScript types. The library uses Redis Streams for state coordination across multiple instances, supports multiple breaker strategies (consecutive, count-based, time-based) and backoff strategies (constant, exponential), includes built-in leader election for health checks, and offers optional Prometheus metrics via @zenvark/prom. It differentiates by focusing on distributed environments with leader election and Redis-backed coordination, unlike single-process circuit breakers.","status":"active","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/zenvark/zenvark","tags":["javascript","zenvark","circuit","breaker","circuit-breaker","redis","distributed","typescript"],"install":[{"cmd":"npm install zenvark","lang":"bash","label":"npm"},{"cmd":"yarn add zenvark","lang":"bash","label":"yarn"},{"cmd":"pnpm add zenvark","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for Redis communication; must be installed separately as a peer dependency.","package":"ioredis","optional":false}],"imports":[{"note":"CircuitBreaker is a named export, not a default export. ESM-only package; no CommonJS support.","wrong":"import CircuitBreaker from 'zenvark'","symbol":"CircuitBreaker","correct":"import { CircuitBreaker } from 'zenvark'"},{"note":"All breaker strategies are exported from the main package entry, not from subpaths.","wrong":"import { ConsecutiveBreaker } from 'zenvark/strategies'","symbol":"ConsecutiveBreaker","correct":"import { ConsecutiveBreaker } from 'zenvark'"},{"note":"The package is ESM-only since v1.2.0. Using require() will cause a runtime error with Node >=22.","wrong":"const CircuitOpenError = require('zenvark').CircuitOpenError","symbol":"CircuitOpenError","correct":"import { CircuitOpenError } from 'zenvark'"},{"note":"Redis client is from the separate ioredis package, not part of zenvark.","wrong":"import { Redis } from 'zenvark'","symbol":"Redis","correct":"import { Redis } from 'ioredis'"}],"quickstart":{"code":"import { Redis } from \"ioredis\";\nimport {\n  CircuitBreaker,\n  ConsecutiveBreaker,\n  ConstantBackoff,\n  CircuitOpenError,\n} from \"zenvark\";\n\nconst redis = new Redis(process.env.REDIS_URL ?? \"redis://localhost:6379\");\n\nconst circuitBreaker = new CircuitBreaker({\n  id: \"my-service-api\",\n  redis,\n  breaker: new ConsecutiveBreaker({ threshold: 5 }),\n  health: {\n    backoff: new ConstantBackoff({ delayMs: 5000 }),\n    async check(type, signal) {\n      const response = await fetch(\"https://api.example.com/health\", {\n        signal,\n      });\n      if (!response.ok) throw new Error(\"Health check failed\");\n    },\n  },\n});\n\nawait circuitBreaker.start();\n\ntry {\n  const result = await circuitBreaker.execute(async () => {\n    return await fetch(\"https://api.example.com/data\");\n  });\n  console.log(\"Success:\", result);\n} catch (err) {\n  if (err instanceof CircuitOpenError) {\n    console.log(\"Circuit is open - request blocked\");\n  }\n}\n\nawait circuitBreaker.stop();","lang":"typescript","description":"Creates a distributed circuit breaker using Redis, with consecutive failure threshold, constant backoff, and health check."},"warnings":[{"fix":"Run 'npm install ioredis' alongside zenvark.","message":"ioredis must be installed as a separate dependency; zenvark does not bundle a Redis client.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use import syntax or set 'type': 'module' in package.json. For Node <22, upgrade to Node >=22 or use a previous version.","message":"The package is ESM-only since v1.2.0 and does not provide a CommonJS entry. Using require() will fail.","severity":"breaking","affected_versions":">=1.2.0"},{"fix":"Use import { CircuitBreaker } from 'zenvark' instead of import CircuitBreaker from 'zenvark'.","message":"All classes (CircuitBreaker, ConsecutiveBreaker, etc.) are named exports, not default exports.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure options.redis is a valid ioredis.Redis instance and options.breaker is one of ConsecutiveBreaker or CountBreaker.","message":"Constructor options for CircuitBreaker require a Redis instance (ioredis) and a breaker strategy. Missing either will cause runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Instantiate a backoff strategy explicitly: new ConstantBackoff({ delayMs: 5000 }).","message":"The 'backoff' option in health config accepts only ConstantBackoff or ExponentialBackoff instances. Passing a plain object may not work as expected.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.2.0':18 'across':35 'applic':13 'avail':12 'back':83 'backoff':50 'base':45,48 'breaker':5,40,90,94,97 'built':56 'built-in':55 'check':62 'circuit':4,89,93,96 'circuit-break':95 'consecut':42 'constant':52 'coordin':6,34,84 'count':44 'count-bas':43 'current':14 'differenti':71 'distribut':3,75,99 'elect':59,79 'environ':76 'exponenti':53 'focus':73 'health':61 'high':11 'high-avail':10 'includ':54 'instanc':37 'javascript':91 'leader':58,78 'librari':28 'metric':67 'multipl':36,39 'npm':22 'offer':64 'option':65 'packag':23 'process':88 'prometheus':66 'redi':8,30,82,98 'redis-back':81 'releas':19 'singl':87 'single-process':86 'stabl':15 'state':33 'strategi':41,51 'stream':31 'support':38 'time':47 'time-bas':46 'type':26 'typescript':25,100 'unlik':85 'use':29 'version':16 'via':7,68 'zenvark':1,92 'zenvark/prom':69","created_at":"2026-06-07T13:01:57.178907+00:00","updated_at":"2026-06-07T13:01:57.178907+00:00","problems":[{"fix":"Run 'npm install ioredis' to add the required peer dependency.","cause":"ioredis is not installed or not in node_modules.","error":"ERR_MODULE_NOT_FOUND: Cannot find package 'ioredis' imported from ..."},{"fix":"Change to import { CircuitBreaker } from 'zenvark'.","cause":"Using default import instead of named import: import CircuitBreaker from 'zenvark'","error":"TypeError: circuitBreaker.start is not a function"},{"fix":"Start Redis server or provide correct REDIS_URL environment variable.","cause":"Redis server is not running or connection string is incorrect.","error":"Error: Redis connection error: connect ECONNREFUSED ..."},{"fix":"Add 'type': 'module' to package.json or rename .js files to .mjs.","cause":"The package is ESM-only and running in a CommonJS project without proper configuration.","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://zenvark.github.io/zenvark","github":"https://github.com/zenvark/zenvark","docs":null,"changelog":null,"pypi":null,"npm":"zenvark","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}