# Circuit Breaker

> Stop hammering a failing service — trip the breaker, fail fast, recover gracefully.

- **Category**: Microservices
- **Subcategory**: Resilience
- **Canonical URL**: https://designpattern.fyi/patterns/circuit_breaker/

---

## Description
Clean, reusable architecture pattern.


## Use Cases
Payment Service is down. Circuit Breaker on Order Service trips after 5 failures. Orders now fail fast with "payment unavailable" instead of hanging for 30s, keeping Order Service healthy for other operations.





## Trade-offs


### Advantages

- Prevents cascade failures — isolates blast radius

- Fail-fast saves threads/resources on the caller side

- Automatic recovery testing via half-open state

- Improves overall system resilience with minimal code change




### Considerations & Drawbacks

- Threshold tuning is tricky — too sensitive = false trips, too loose = too slow to protect

- Half-open state needs careful handling to avoid thundering herd

- Adds complexity to call paths

- Needs coordination with fallback logic (what do you return when open?)







---
**Reference**: [Original Source](https://microservices.io/patterns/reliability/circuit-breaker.html)

