liveBook · Manning

Circuit breaker pattern

As explained in Secure APIs

A circuit breaker pattern prevents repeated calls to an unhealthy dependency and returns a controlled result when that dependency fails or responds unexpectedly.

A circuit breaker prevents repeated calls to an unhealthy dependency, such as an internal service or third-party API. An outbound proxy monitors the dependency and returns a useful error when it times out, stops responding, or behaves unexpectedly, limiting cascading failures. section 5.7

Third-party API failure

Suppose an application depends on a third-party API that becomes unavailable or returns malformed data. Without protection, errors can reach application servers or cause corrupted database writes. A circuit breaker stops sending calls after unhealthy responses and returns a controlled result, while graceful degradation keeps the application operating where possible. section 5.7

Pair the circuit breaker with defensive handling of consumed API data:

  • Validate and sanitize external responses at runtime; reject invalid data and contact the API provider. section 5.7
  • Build validation models from documented OpenAPI response schemas and parameterize database queries involving external data. section 5.7

How Secure APIs covers it

How deep it goes
Defines proxy-based health monitoring and controlled errors, but does not detail circuit states or implementation code.
Examples
Uses unavailable or malformed third-party API responses and an outbound proxy that returns a useful error.
What it assumes
Assumes familiarity with consuming internal or external APIs and teaches defensive handling of their failures and responses.
What you can do after
Apply it by monitoring dependencies, returning controlled errors, degrading gracefully, and validating consumed responses.
How it connects
Connects cascading failures with graceful degradation, outbound proxies, response validation, OpenAPI, and SQL injection prevention.

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 Secure APIs. The section links point to the parts of the book it draws on.