分散システムでは、すべてはやがて失敗します。レジリエンスパターンは、単一の障害がシステム全体の停止に広がるのを防ぎます。
const breaker = new CircuitBreaker(callPaymentService, {
timeout: 3000, // fail the call after 3s
errorThresholdPercentage: 50, // open if >50% of calls fail
resetTimeout: 10000 // after 10s, try one request (half-open)
});
breaker.fallback(() => ({ status: 'queued' })); // graceful degradation
CLOSED ──(failures exceed threshold)──▶ OPEN
▲ │ (after resetTimeout)
│ (trial succeeds) ▼
└────────────── HALF-OPEN ◀──────────────┘
(one trial request)
[ pool A: 10 threads ] → payment calls
[ pool B: 10 threads ] → search calls
If search hangs, it drains pool B only — payments keep working.
バックオフなしのリトライは、すでに負荷がかかっているサービスへの負荷を増幅させます(リトライストーム)。常にバックオフ、ジッター、リトライの上限を追加します。
これらのパターンは、避けられない単一サービスの障害をサイト全体の停止ではなく、機能の低下に変えます。
これらは一緒に機能します。タイムアウトは待機時間を制限し、サーキットブレーカーは停止サービスへの呼び出しを停止し、バルクヘッドは影響範囲を限定し、リトライは一時的な問題から回復します — いずれかを省略すると、障害は継続して拡大します。
ジュニアからシニアまで、詳細な回答付きのIT面接質問ライブラリ。
寄付する