Systems & Backend

Circuit Breaker

Stop calling a failing dependency; fail fast, probe for recovery — the pattern that prevents cascade failures.

A circuit breaker watches calls to a dependency. Too many failures → the breaker opens and calls fail instantly (or fall back) instead of stacking up timeouts. After a cooldown it goes half-open, letting probe requests test recovery before closing again. It protects both sides: your threads aren’t blocked, and the struggling service isn’t hammered while it heals. Pairs with retries-with-backoff and backpressure.

Worked example: a circuit breaker trips after N consecutive failures to a dependency, then ‘opens’ to fail fast for a cooldown instead of hammering a dying service; after the cooldown it half-opens to test recovery. Gotcha: it prevents cascading failure (a slow dependency exhausting your threads), but tune the thresholds — too sensitive and it trips on transient blips, too lax and it never protects you.