Skip to content
System Design Explorer
reliability

Circuit Breaker

By Ankur NayakReviewed

A circuit breaker stops a service from repeatedly calling a dependency that is failing. After too many errors it fails fast, often with a fallback, and later lets a few trial requests through to see whether the dependency has recovered.

Circuit Breaker diagramComponents: API Service, Circuit Breaker, Recommendations, Fallback Cache. Connections: API Service to Circuit Breaker; Circuit Breaker to Recommendations (closed: call through); Circuit Breaker to Fallback Cache (open: fallback).API ServiceServiceCircuit BreakerServiceRecommendationsServiceFallback CacheCache
Failing fast with a fallback

How it works

In a microservice system, one slow dependency can exhaust threads and connections in every caller, spreading a local failure into an outage. A circuit breaker wraps calls to a dependency and tracks their failures and timeouts.

It has three states. Closed: calls go through and failures are counted. Open: after a threshold is crossed, calls fail immediately without touching the dependency, giving it room to recover. Half-open: after a cool-down, a few trial calls go through; success closes the circuit again, failure re-opens it.

Failing fast is only half the value. A good fallback (a cached value, a default, or a degraded feature) keeps the user experience mostly intact. Netflix popularised the pattern in its Hystrix library.

Key points

  • Closed → open → half-open
  • Fail fast instead of piling up timeouts
  • Pair with timeouts, bulkheads and fallbacks
  • Tune thresholds per dependency

When to use it, and pitfalls

Use it for

  • Calls to remote services, databases or third-party APIs
  • Any dependency whose failure should not take the caller down

Watch out for

  • Fallbacks that call another fragile dependency
  • Thresholds so sensitive that normal error spikes open the circuit
  • Retries without backoff that hammer a recovering service

Used in

Frequently asked questions

What is the difference between a retry and a circuit breaker?

Retries assume a failure is brief and try again. A circuit breaker assumes repeated failures mean the dependency is unhealthy and stops calling it for a while. They work together: retry a few times with backoff, and let the breaker stop retries when failures persist.

Sources