liveBook · Manning

Circuit breaker pattern

As explained in Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

A circuit breaker is a resilience pattern that stops requests to a failing upstream service and resumes them after checking that the service has recovered.

A circuit breaker protects a microservice from repeatedly calling a failing upstream service. It acts like an advanced timeout: after a request fails, it stops sending new requests and fails them immediately. section 11.4.7

The circuit follows a small state machine:

  • On: normal requests pass through to the upstream resource. section 11.4.7
  • Off: new requests fail immediately because the upstream service is known to be failing. section 11.4.7
  • Recovery check: after a configurable delay, the breaker checks the upstream service and returns to On when normal operation resumes. section 11.4.7

Failing upstream service

A request to a particular HTTP resource fails, so the breaker switches Off. Subsequent callers receive an immediate failure instead of waiting for another timeout. After its configured delay, the breaker checks the service and permits requests again when it has recovered. section 11.4.7

Figure 11.16 Illustrating how the circuit breaker works

Use the state-transition figure to trace normal requests, failure detection, immediate rejection, recovery checks, and the return to normal traffic. section 11.4.7

Circuit breakers are harder to implement than timeouts or retries, but they prevent repeated slow failures and are useful when an upstream dependency is persistently unhealthy. section 11.4.7 section 11.6

How Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform covers it

How deep it goes
Explains On and Off states, recovery checks, and configurable delays, but stops short of implementation details.
Examples
Uses a failed HTTP request to a particular resource, immediate subsequent failures, and a delayed upstream recovery check.
What it assumes
Assumes familiarity with timeouts and retries as related network fault-tolerance techniques.
What you can do after
Evaluate/understand when state-based fast failure can protect a service from a failing upstream dependency.
How it connects
Combines timeouts and retries within broader fault-tolerance practices for microservices.

Also explained in

Compare how 6 books explain circuit breaker pattern →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform. The section links point to the parts of the book it draws on.