今日已更新 373 条资讯 | 累计 24659 条内容
关于我们

Node.js has plenty of circuit breakers. So why did I build another one?

Pedro Rogério 2026年07月27日 20:40 1 次阅读 来源:Dev.to

Every service I've worked on eventually grows the same scar tissue: a retry loop copy-pasted into six files, a circuit breaker bolted onto the payment client after an outage, a timeout wrapper someone wrote at 3 a.m. Each one slightly different. None of them talking to each other. And when things go wrong, nobody can answer the only question that matters during an incident: what is the resilience layer actually doing right now? Java solved this years ago with resilience4j . .NET has Polly . Node.js... has pieces. The gap I evaluated what the ecosystem offers before writing a single line: opossum is the best-known circuit breaker, mature and well maintained. But it's only a circuit breaker — retry is rudimentary, there's no bulkhead, no composition. Metrics need a plugin. cockatiel is the closest thing to Polly: retry, breaker, timeout, bulkhead, composition. I genuinely like its design. But observability is where it stops — no native metrics, no pipeline-wide correlation — and maintenance has slowed. The Sindre micro-libs ( p-retry , p-timeout , p-limit ) are excellent at exactly one thing each. But resilience is a system : a retry that doesn't know the circuit is open will happily sleep through backoff to hammer a dead dependency. Isolated pieces can't coordinate. And there was one thing nobody documented properly, which became the reason I finally started typing: Ordering is the whole game Take four policies: retry, circuit breaker, timeout, fallback. The same four, nested in two different orders, produce two very different systems: retry ( circuitBreaker ( timeout ( fn ) ) ) // A circuitBreaker ( retry ( timeout ( fn ) ) ) // B In A , every attempt flows through the breaker, so the breaker sees the dependency's true failure rate — and when the circuit opens mid-retry, the retry finds out immediately. In B , the breaker sees one outcome per retry cycle : three real failures against the dependency count as a single failure. The circuit opens far later than the depe

本文内容来源于互联网,版权归原作者所有
查看原文