Skip to content

What is a Circuit Breaker? — Preventing Cascade Failures in Go

The circuit breaker pattern, popularized by Michael Nygard in “Release It!” (2007), protects a service from being dragged down by a failing dependency. Named after the electrical circuit breaker that interrupts current when it detects a fault, the software pattern monitors calls to an external service and stops sending requests when failures exceed a threshold — giving the downstream system time to recover and preventing your service from exhausting resources waiting on timeouts.

Without a circuit breaker, a slow or failed external service causes your goroutines to pile up waiting on connections that will never complete. Each blocked goroutine holds memory. Eventually the thread pool (or goroutine scheduler overhead) saturates, your service becomes unresponsive, and the failure cascades to your callers. The circuit breaker breaks this chain.

The circuit breaker is a state machine with three states:

CLOSED → Normal operation. Calls pass through. Tracks failure rate.
OPEN → Failures exceeded threshold. Calls fail immediately (no network call).
HALF-OPEN → After a timeout, allows one probe request through.
Success → CLOSED. Failure → back to OPEN.

The trip threshold is typically a combination of failure count and failure rate over a time window. A circuit that trips on a single failure is too sensitive; one that never trips defeats the purpose.

verikt’s circuit-breaker capability scaffolds a wrapper around your outbound HTTP client or service call:

cb := circuitbreaker.New(circuitbreaker.Config{
MaxFailures: 5,
Timeout: 30 * time.Second,
HalfOpenMax: 1,
})
result, err := cb.Do(ctx, func() (any, error) {
return paymentClient.Charge(ctx, req)
})
if errors.Is(err, circuitbreaker.ErrOpen) {
return nil, ErrPaymentServiceUnavailable
}

When ErrOpen is returned, the caller can respond immediately with a degraded response instead of waiting for a timeout.

The circuit-breaker capability is scaffolded as part of the resilience toolkit. verikt warns when http-client is used without circuit-breaker — a slow external service without a circuit breaker is a cascade failure waiting to happen. See the Capabilities Matrix for the full warning list.

Bulkhead Pattern

Isolates failure domains by limiting concurrency — complements the circuit breaker. Bulkhead Pattern

Rate Limiting

Controls inbound traffic rate — circuit breaker manages outbound failure propagation. Rate Limiting

Idempotency

When the circuit reopens and retries begin, idempotency prevents duplicate operations. Idempotency