Circuit Breaker

Definition

The Circuit Breaker design pattern prevents cascading failures in distributed systems by stopping calls to failing services, enhancing system resilience.

Use Cases

Frequently Asked Questions

What's the difference between Circuit Breaker and Retry?
Retry keeps trying a failed request (often with backoff) because the failure might be temporary. A Circuit Breaker stops sending requests after failures cross a threshold, giving the failing service time to recover and protecting your system from wasting resources. In practice, you often use both: limited retries for transient errors, plus a circuit breaker to prevent endless pressure on an unhealthy dependency.
When should I use a Circuit Breaker in microservices?
Use it when your service calls another service (or database/third-party API) and failures or slow responses could tie up threads, connection pools, or CPU and cause a wider outage. It’s especially useful for synchronous HTTP/gRPC calls, high-traffic paths (checkout, login), and dependencies with variable reliability. If a dependency is optional, pair the circuit breaker with a fallback (cached data, default response, queued work) to keep your service responsive.
How much does a Circuit Breaker cost?
The pattern itself is usually free if implemented in application code using open-source libraries (e.g., Resilience4j for Java, Polly for .NET). Costs come from operational overhead: extra monitoring/metrics, potential service-mesh or API gateway licensing/usage, and engineering time to tune thresholds and fallbacks. If implemented via a managed gateway/mesh, pricing depends on request volume, compute, and any paid platform features.

Category: software

Difficulty: advanced

Related Terms

See Also