Circuit Breaker

斷路器是一種設計模式,用於防止微服務系統中的連鎖故障。當一個服務持續發生故障時,斷路器會自動「斷開」,停止向有問題的服務發送請求,轉而快速返回錯誤響應或備用方案,避免耗盡系統資源和影響其他服務。

States

  • Closed - Normal operation, requests flow through
  • Open - Circuit is tripped, requests fail fast
  • Half-Open - Testing if the service has recovered

Benefits

  • Prevents cascading failures
  • Provides fallback mechanisms
  • Allows services to recover gracefully
  • Reduces system resource exhaustion