#πŸ“ Note: Circuit Breaker Pattern

#Overview

The Circuit Breaker pattern prevents a system from repeatedly trying to execute an operation that is likely to fail, allowing it to recover gracefully without cascading failures across services.

#Core Idea

Inspired by electrical circuit breakers β€” when a downstream service is failing, "open the circuit" to stop sending requests, give it time to recover, and serve degraded/fallback responses instead.

#States

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     Failure threshold    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  CLOSED  β”‚ ──────exceeded────────▢ β”‚   OPEN   β”‚
β”‚ (normal) β”‚                          β”‚ (failing)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                          β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
     β–²                                      β”‚
     β”‚            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”‚
     β”‚ Success    β”‚ HALF-OPEN β”‚  Timeout    β”‚
     └────────────│ (testing) β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚ Failure
                     └──────────▢ Back to OPEN

#Configuration Parameters

Parameter Typical Value Purpose
Failure Threshold 5 failures in 30s When to trip the circuit
Open Timeout 30–60 seconds How long to wait before testing recovery
Half-Open Max Requests 3–5 requests How many test requests to allow
Success Threshold 3 consecutive How many successes needed to close circuit

#When to Use

#Fallback Strategies

#Trade-offs

#Used In This Repo