Loading pattern...

What is Circuit Breaker?

Circuit Breaker stops calling a failing service to prevent cascading failures. Like an electrical circuit breaker—if a service fails repeatedly, "trip" the circuit and return cached/default response instead of waiting for timeouts. After cooldown period, try again. States: Closed (working), Open (failing, don't call), Half-Open (testing if recovered). Prevents one failing service from taking down entire system.

When Should You Use This?

Use circuit breakers in microservices when calling external services (payment APIs, email services) that might fail, when one slow service could cascade and take down your app, or when you want graceful degradation (show cached data if real-time fails). Essential for resilient systems. Implement with libraries like Hystrix, resilience4j, or cloud services.

Common Mistakes to Avoid

  • No fallback—circuit breaks, but you show user an error instead of degraded experience
  • Wrong thresholds—too sensitive (breaks on one failure) or too lenient (cascades anyway)
  • No monitoring—circuit breaker trips, no one notices
  • Synchronous retry—circuit opens, immediately retry makes it worse
  • All-or-nothing—partial failures should allow partial functionality

Real-World Examples

  • Netflix—Circuit breakers prevent one failing microservice from cascading
  • Stripe—Payment processing has circuit breakers, falls back to queue if service down
  • E-commerce—Recommendation service breaks, show popular items instead of error
  • Social media—Timeline service fails, show cached posts instead of blank page

Category

System Design Patterns

Tags

circuit-breakerresiliencefault-tolerancemicroservicessystem-design

Permalink