Circuit breaker

서킷 브레이커

Pause calls after repeated failures, then probe for recovery.

···
html
<div class="scene"><div class="title">CIRCUIT STATE MACHINE</div><div class="row breaker"><div class="tile">CALLER</div><div id="gate" class="gate">CLOSED</div><div class="tile">SERVICE</div></div><div id="result" class="result">Request passes → response</div><div class="states"><span id="closed">CLOSED</span><span id="open">OPEN</span><span id="half">HALF-OPEN</span></div></div>
css
.scene{width:min(94vw,760px);height:min(86vh,320px);padding:clamp(10px,2.5vmin,18px);border:1px solid var(--line);border-radius:14px;background:var(--surface);color:var(--fg);font:500 clamp(11px,1.3vw,16px)/1.25 "Pretendard Variable",Pretendard,-apple-system,sans-serif;display:flex;flex-direction:column;gap:clamp(7px,1.6vmin,12px);overflow:hidden}.scene *{box-sizing:border-box}.title{font-weight:750;color:var(--accent)}.muted{color:var(--muted)}.mono{font-family:ui-monospace,monospace}.row{display:flex;align-items:center;justify-content:center;gap:clamp(5px,1.4vmin,12px);flex:1;min-height:0}.tile{border:1px solid var(--line);border-radius:8px;background:var(--bg);padding:clamp(6px,1.6vmin,12px);text-align:center;min-width:0}.on{border-color:var(--accent)!important;background:color-mix(in srgb,var(--accent) 12%,var(--surface))!important}.pulse{animation:pulse 1.6s infinite alternate}@keyframes pulse{to{border-color:var(--accent);transform:translateY(-3px)}}.breaker .tile{flex:1}.gate{border:2px solid var(--accent);border-radius:50%;width:29%;aspect-ratio:1;max-height:95px;display:grid;place-items:center;color:var(--accent);text-align:center}.result{padding:6px;background:var(--bg);border-radius:5px;text-align:center}.states{display:flex;justify-content:space-between;gap:4px;font-size:clamp(11px,1.2vw,14px)}.states .on{color:var(--accent);font-weight:750}
js
const states=['CLOSED','OPEN','HALF-OPEN'];let n=0;function tick(){const s=states[n%3];document.getElementById('gate').textContent=s;document.getElementById('result').textContent=['Request passes → response','Calls fail fast; remote spared','One probe checks recovery'][n%3];['closed','open','half'].forEach((id,i)=>document.getElementById(id).classList.toggle('on',i===n%3));n++}tick();setInterval(tick,1000)

A circuit breaker opens after repeated remote failures and rejects further calls quickly. After a wait it enters a half-open state and allows a small probe to test recovery.

The demo cycles through closed, open, and half-open routes. Failure thresholds and recovery delays need tuning for the service.

When to use

Use it when an unstable remote dependency could cascade delay to callers.

Open as page ↗