All the basics

What is a circuit breaker?

When a service you depend on keeps failing, stop calling it for a while and fail fast, so trouble does not spread.

A fuse box flips its switch off when too much current surges in, cutting the wire so the house is safe. A breaker does that for calls.

Press Play to watch it run · 5 steps

Customers use your app, which calls a pricing service that is failing, through a breaker.

A failing service and a breakerCustomers use your app, which calls a pricing service that is failing, through a breaker.CustomersYour appBreakerPricing service

Tap any box to see what it is and what it talks to.

  • Client
  • Service
  • API gateway
  • External API
Open in playground
Text description
  1. The pricing service is struggling, but customers keep arriving.
  2. With no breaker, every request goes straight through to the service.
  3. The service is stuck. Each call waits 30 seconds, then fails.
  4. Waiting calls pile up and use up the app's workers.
  5. Now every page is slow, even ones that never needed prices.
  • Waiting on a dead service hurts you more than failing fast.
  • After a few failures, the breaker stops calls for a while.
  • It later lets one test call through to check recovery.

Reach for it when

When a slow outside service, like pricing or payments, could tie up every worker waiting on it. Not for fast local code.

The catch

Trip too early and good calls get a fallback for 30 seconds; trip too late and workers have already piled up.

Say it in an interview“I would wrap remote calls in a circuit breaker with a timeout. After repeated failures it fails fast, serves a fallback, and probes the service before closing again.”