Skip to content

Circuit Breaker (Networking)

Medium — good to knowNetworking

ELI5 — The Vibe Check

A circuit breaker monitors calls to a service and 'trips' when too many fail. Once tripped, it stops sending requests and fails fast instead of waiting for timeouts. After a cooldown, it lets a few test requests through to see if the service recovered. It's a fuse box for your API calls.

Real Talk

A resilience pattern that monitors external service calls and opens the circuit (stops sending requests) when failures exceed a threshold. States: Closed (normal operation), Open (all calls fail fast), Half-Open (limited test requests). This prevents cascade failures, reduces latency from timeouts, and gives failing services time to recover.

Show Me The Code

// Using a circuit breaker library
const breaker = new CircuitBreaker(callExternalAPI, {
  failureThreshold: 5,     // Open after 5 failures
  resetTimeout: 30000,     // Try again after 30s
  successThreshold: 3,     // Close after 3 successes
});

try {
  const result = await breaker.fire(params);
} catch (e) {
  // Circuit is open — use fallback
  return cachedResult;
}

When You'll Hear This

"The circuit breaker tripped after the payment service went down — now we fail fast instead of timing out." / "Set the circuit breaker threshold based on your SLA — too sensitive and it trips on normal errors."

Made with passive-aggressive love by manoga.digital. Powered by Claude.