サーキットブレーカー
リモートサービスやリソースへのアクセスを、障害が閾値に達した時点で一時的に遮断し、繰り返しの失敗とリトライを防ぐパターンです。
構造と動作原理
矢印をステップごとに確認します。
失敗が続いた場合は呼び出しを遮断し、限られた試行リクエストで回復を確認します。
期待できる効果
障害の影響を限定し、障害中のサービスへのリトライで消費するリソースを減らします。
トレードオフ
閾値を低く設定しすぎると、一時的な揺らぎでも誤って回路が開く可能性が高まります。
入力検証など、高いエラー率が仕様上正常なサービスには向きません。
運用・適用ガイド
総合説明であり、原文の裏付けがある項目とは区別しています。実環境で使用する前に検証してください。
使いどころ
マイクロサービス間のリモート呼び出しが繰り返しタイムアウトするか 5xx を返す場合に使います。呼び出しを一時遮断し、半開状態で依存先の回復を試します。
シナリオ
大規模な EC の注文 API が、在庫・決済・通知サービスを同期呼び出しする例です。決済の遅延が急増すると、注文 API のスレッドや接続が枯渇し、すべての注文が失敗しかねません。決済呼び出しにブレーカーを設け、エラー率が閾値を超えたら速やかにフォールバックし、半開状態では限られたリクエストで回復を確認します。注文成功率の維持、障害の波及防止、運用アラートとダッシュボードでの可視化が要件です。
配置の原則
- ゲートウェイやエッジで集中管理する
- ルーティング・可観測性・ポリシーとともにサービスメッシュやサイドカープロキシに配置する
- クライアントライブラリとして呼び出し側に組み込む
- 複数クラスタやリージョンでは、共有ストレージを使った分散コーディネーターで状態を調整する。
オンプレミス
サービスメッシュや API ゲートウェイをオンプレミスの Kubernetes または VM に配置し、依存先ごとの閾値、タイムアウト、フォールバックを環境に合わせて調整します。まず、設定の集中配布経路と可観測性の構成を標準化します。
クラウド
マネージド Kubernetes、サービスメッシュやゲートウェイのポリシーで構成します。デプロイやアップグレード中のブレーカー状態とフォールバックを監視し、マネージドメトリクス、アラート、オートスケーリングと連携させます。
Kubernetes
Istio DestinationRule の OutlierDetection、サービスメッシュのサーキットブレーカーポリシー、または Hystrix、Resilience4j、opossum などのライブラリで実装します。閾値やリセットまでの待機時間を ConfigMap や CRD で管理し、Pod やノードのドレイン時およびロールアウト中の状態遷移を監視します。
障害対応
主な障害は、依存先の遅延・エラー急増、誤検知による遮断、半開での回復失敗、フォールバック障害、通知のない遮断です。アラートとメトリクスでブレーカーの状態や依存先の SLO を確認し、閾値・タイムアウト・フォールバックの設定と直近のデプロイを点検します。必要に応じて手動で回路を開くか、迂回・分散させ、緩和後は半開からの回復を確認して再発防止の調整を行います。
14の観点別の根拠
調査時点の根拠の有無です。出典が正確で最新かどうかは別途判断してください。
定義・概要根拠あり
リモートサービスやリソースへのアクセスを、障害が閾値に達した時点で一時的に遮断し、繰り返しの失敗とリトライを防ぐパターンです。
Temporarily block access to a remote service or resource after failures reach a threshold解決する課題根拠あり
分散環境のリモート呼び出しで、一時障害、過負荷、遅延、タイムアウトが連鎖障害に広がるのを抑えます。
In a distributed environment, calls to remote resources and services can fail because of transient faults.主要コンポーネント・リソース根拠あり
タイムアウト、エラー率の閾値(%)、リセットまでの待機時間、フォールバックなどで構成します。
const options = { timeout: 3000, errorThresholdPercentage: 50, resetTimeout: 30000, fallback: () => 'Service temporarily unavailable' };データ・アセットの配置根拠あり
ゲートウェイやエッジで集中的に制御し、保護します。
Gateway-level breaker: centralized control at edge, protects ...代表的なユースケース根拠あり
マイクロサービスのリモート呼び出しが繰り返しタイムアウトしたり失敗したりすると、呼び出しを遮断し、依存先の回復を検知します。
When multiple microservices collaborate to handle requests, one or more services might become unavailable or exhibit high latency.シナリオ例根拠あり
可観測性ダッシュボードやコネクターの障害時に、パイプラインからのログ呼び出しを遮断する例です。
Pipelines interact with dashboards, like Sumo Logic or ELK Stack to log key performance indicators (KPIs)不向きな状況・注意点根拠あり
入力検証など、高いエラー率が仕様上正常なサービスには向きません。
User input validation services may reject `30%` of requests. A circuit breaker would stay permanently open.オンプレミス(開発・デプロイ・運用)根拠あり
オンプレミスでは、コンテナや VM のワークロードに対し、サービスメッシュやゲートウェイで運用します。
Deploy Kong Mesh anywhere: on Kubernetes, in the cloud, on-premises, with containers or on virtual machines.クラウド(開発・デプロイ・運用)根拠あり
クラウドのマネージド Kubernetes をアップグレードする際に、ブレーカーの状態とフォールバックを監視します。
// Monitor circuit breaker state during upgradesKubernetes(開発・デプロイ・運用)根拠あり
Kubernetes では Istio DestinationRule の OutlierDetection などを使用できます。
For configuring a circuit breaker in Istio we are using `OutlierDetection` object.障害対応根拠あり
通知のない遮断やフォールバック失敗は発見を遅らせます。状態遷移の監視・通知、依存先の健全性確認が必要です。
Silent trips: The breaker stays “Open” and serves degraded responses for an extended period while emitting no state-transition metric or alert長所根拠あり
障害の影響を限定し、障害中のサービスへのリトライで消費するリソースを減らします。
The benefit of this pattern is that it limits the consequences of a failure by wrapping the interface to that element短所・トレードオフ根拠あり
閾値を低く設定しすぎると、一時的な揺らぎでも誤って回路が開く可能性が高まります。
The lower the `error_threshold`, the higher the probability of a false-positive circuit open.代表的な技術・ツール根拠あり
代表例として Hystrix や Ribbon が挙げられます。
This example demonstrates how to use Hystrix circuit breaker and the Ribbon Load Balancing.その他の参考文献 (22)
- Circuit Breaker Pattern - Azure Architecture Center | Microsoft Learn ↗
- Circuit breaker pattern - AWS Prescriptive Guidance ↗
- What is Circuit breaker? Meaning, Architecture, Examples, Use Cases, and How to Measure It (2026 Guide) - SRE School ↗
- Circuit Breaker: How to Keep One Failure from Taking Down Everything ↗
- Implementing the Circuit Breaker pattern - .NET | Microsoft Learn ↗
- The Circuit Breaker Pattern - Dos and Don'ts — AKF Partners ↗
- docs/operations/failurehandling.md ↗
- Tactics and Patterns for Software Robustness | CMU Software Engineering Institute ↗
- Dynamic configuration management and circuit breakers in Kubernetes - rastko ↗
- Azure Kubernetes Service (AKS) production upgrade strategies - Azure Kubernetes Service | Microsoft Learn ↗
- ECS vs Kubernetes: Paying for Portability Up Front ↗
- Istio and mTLS — securing and observing your service mesh ↗
- Kong Mesh: Enterprise Service Mesh for Kubernetes | Kong Inc. ↗
- Kubernetes Circuit Breaker & Load Balancer Example ↗
- Circuit breaker and retries on Kubernetes with Istio and Spring Boot ↗
- Zero-Downtime Migration to Azure Kubernetes Service (AKS) - Azure Kubernetes Service | Microsoft Learn ↗
- Your Circuit Breaker is Misconfigured - Shopify ↗
- Circuit Breaker | arc42 Quality Model ↗
- Circuit Breaker Policy Fine-tuning Best Practice - .NET Blog ↗
- Circuit Breaker Trade Offs: When Not to Use Them ↗
- Learn Trade-Offs and Limitations of Circuit Breakers | Designing Resilient Architectures ↗
- Google SRE - Troubleshooting Methodology: A Learning Path ↗