All labs
Lab 34
Resilience Patterns

Circuit Breaker — Closed, Open & Half-Open

A failing provider, a live request stream, and the breaker's state machine. Without it, every call waits the full timeout then fails. With it, repeated failures trip the breaker OPEN (calls fast-fail to fallback), a cooldown ticks, then HALF-OPEN probes decide whether to close again. Watch the states flip in real time.

The flight provider is failing. Watch the breaker trip OPEN, fast-fail every call to a fallback, then probe in HALF-OPEN. Flip the provider back to healthy and watch a probe CLOSE the circuit automatically.
CLOSED
calls flow to the provider
0/4 fails
OPEN
calls fast-fail to fallback
HALF-OPEN
one probe call is allowed
Closed —4 fails→ Open —5 ticks→ Half-Open —probe ok→ Closed (probe fails→ Open)
Request stream (newest →)
🟢 success🔴 provider failed⚪ short-circuited (fallback)🟡 probe
Breaker state
CLOSED
Provider calls
0
Fast-failed (saved)
0
calls the breaker spared the provider
State transitions
// watching for failures…

Watch with the breaker OFF first: a failing provider gets called on every request (look at "Provider calls" climb). Turn it ON and the breaker trips after 4 failures — calls stop hitting the provider and fast-fail instead.

What just happened