Circuit breaker pattern for external API dependencies
Why it matters
When an external API — payment gateway, SMS provider, identity service — starts returning errors, repeated synchronous retries amplify load on an already-struggling service and cascade failures throughout your application. CWE-703 (improper check for exceptional conditions) applies to this failure mode. ISO 25010 reliability.fault-tolerance requires the system to degrade gracefully under component failures; a missing circuit breaker means one downstream outage can freeze all request-handling threads or queue workers indefinitely, taking down your entire service.
Severity rationale
Medium because without circuit-breaking, a single downstream API failure causes cascading thread exhaustion or queue saturation across the entire application.
Remediation
Use the opossum library for Node.js or implement a minimal hand-rolled breaker for fetch-based calls. The breaker must track failure rate and reject calls when the circuit is open.
// lib/circuit-breaker.ts
import CircuitBreaker from 'opossum'
export function createBreaker<T>(fn: (...args: unknown[]) => Promise<T>) {
return new CircuitBreaker(fn, {
timeout: 5000, // fail after 5s
errorThresholdPercentage: 50, // open at 50% failure rate
resetTimeout: 30000, // retry after 30s
})
}
// Usage:
const breaker = createBreaker(callPaymentAPI)
const result = await breaker.fire(payload)
Wrap the three highest-traffic external integrations first: payment, auth, and any real-time data feed.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Error Resilience Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-703 — Improper Check or Handling of Exceptional Conditions
- iso-25010:2011 · reliability.fault-tolerance
Taxons
History
- 2026-04-18·v1.0.0·Initial import from error-resilience·automated