The circuit breaker pattern prevents cascading failures in distributed systems. When calls to a service start failing, the circuit 'opens' — subsequent calls fail immediately without attempting the request. After a timeout, it 'half-opens' to test if the service recovered.

How Circuit Breaker Works

Payment service calls fail 5 times in 10 seconds → circuit opens → next 30 seconds of payment calls return fallback (queued for retry) without hitting the failing service → after 30 seconds, one test call is allowed → if it succeeds, circuit closes and normal traffic resumes.

Key Concepts

  • Closed — Normal operation — requests flow through, failures are counted
  • Open — Service is failing — requests immediately return error/fallback without attempting the call
  • Half-Open — After timeout, allow one test request — if it succeeds, close; if it fails, open again

Frequently Asked Questions

When do I need a circuit breaker?

When your service calls external services or microservices. Without circuit breakers, a slow/failed dependency can cascade failures through your entire system.