liveBook · Manning

Circuit breaker pattern

As explained in Grokking Software Architecture

A circuit breaker is a resilience pattern that temporarily prevents calls to a failing dependency to limit cascading failures.

Imagine a payment API going offline during checkout. If every request waits for a timeout, blocked threads and rising memory use can bring down your application too. A circuit breaker acts like an electrical breaker: it cuts the connection before a local failure spreads. section 10.3

A circuit breaker wraps calls to a dependency and monitors errors and timeouts. When failures cross a configured threshold, it opens and blocks further calls, returning an error or triggering a fallback immediately. This saves resources and gives the dependency breathing room to recover. section 10.3 section 10.3.2

The breaker moves between three states:

  • Closed: Calls pass through normally while the breaker counts failures. A closed circuit is connected, not blocked. section 10.3.1
  • Open: After the failure threshold is reached, calls are intercepted and fail fast. A threshold might be five consecutive failures or a 50% failure rate over 30 seconds. section 10.3.2
  • Half-open: After a cooldown, one test request passes through. Success closes the breaker and restores normal traffic; failure reopens it and restarts the cooldown. section 10.3.3
Figure 10.4 The Circuit Breaker Pattern: Failing fast to prevent a localized dependency failure from cascading and burning down your entire application.

See how failing fast keeps a dependency failure from cascading through the application. section 10.3

Avoiding a retry storm

A brief payment API delay can turn a tight retry loop into thousands of immediate requests, adding pressure to an already struggling service. A circuit breaker stops calls when the service is failing; exponential backoff with jitter spaces retries instead of firing them all at once. section 12.8.3

A breaker is one part of a resilience plan, not a substitute for every safeguard. Timeouts limit individual waits, fallbacks offer a plan B, and bulkheads isolate resources so one dependency cannot consume all available capacity. section 10.10 section 10.3.3

How Grokking Software Architecture covers it

How deep it goes
Explains failure thresholds and all three state transitions, including a cooldown and test request.
Examples
Illustrates an unavailable payment API at checkout and a retry loop that amplifies a brief delay.
What you can do after
Evaluate and understand how a circuit breaker limits cascading failures and tests for recovery.
How it connects
Connects circuit breakers with timeouts, fallbacks, bulkheads, retries, and exponential backoff.

Also explained in

Compare how 14 books explain circuit breaker pattern →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.