{
  "id": "circuit-breaker-pattern",
  "title": "Circuit Breaker Pattern",
  "lang": "en",
  "source_lang": "en",
  "summary": "The circuit breaker pattern temporarily blocks calls to a failing dependency, limiting cascading failures and allowing controlled checks for recovery.",
  "category": "computer-science",
  "subcategory": "software",
  "type": "concept",
  "aliases": [
    "Circuit breaker",
    "Software circuit breaker"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/circuit-breaker-pattern/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/circuit-breaker-pattern/",
      "json": "https://aiwiki.page/zh/circuit-breaker-pattern.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "The circuit breaker pattern is a software architecture pattern that monitors calls to an operation or dependency and temporarily stops forwarding them when failures exceed a configured threshold. While the breaker is open, calls fail quickly or follow an explicitly defined fallback rather than repeatedly invoking the failing dependency. After a waiting period, the breaker usually admits a limited number of trial calls to determine whether normal operation can resume. The pattern is widely used in distributed systems, where failures and excessive delays can propagate across service boundaries."
    },
    {
      "heading": "Purpose and operating context",
      "text": "A remote call can fail because of network disruption, overload, unavailable infrastructure, or an error in the receiving service. A particularly damaging failure is a dependency that responds slowly: callers may continue waiting while consuming connections, memory, execution slots, or other limited resources. If those resources are exhausted, an otherwise healthy caller can become unavailable to its own clients.\n\nIn systems composed of microservices, this effect can spread through a chain of dependencies. Repeated attempts can further increase pressure on a dependency that is already struggling. A circuit breaker interrupts this feedback by withholding calls once recent results indicate that continued attempts are unlikely to succeed.\n\nTypical protected operations include requests to an external API, calls to another service, and selected database operations. The breaker generally belongs at a boundary where failures can be observed and classified, rather than around arbitrary internal code.\n\nThe electrical analogy explains the terminology: a closed circuit permits flow, while an open circuit interrupts it. A software breaker, however, normally responds to observed call outcomes rather than electrical current, and it often tests recovery automatically."
    },
    {
      "heading": "State model",
      "text": "A conventional circuit breaker is a finite-state machine with three states.\n\nState | Treatment of incoming calls | Typical transition\nClosed | Calls are permitted and their outcomes are recorded. | Opens when a failure or slow-call threshold is reached.\nOpen | Calls are rejected without invoking the protected operation. | Becomes half-open after a configured waiting period.\nHalf-open | A limited number of trial calls are permitted. | Closes after sufficient evidence of recovery, or reopens if trials fail.\n\nClosed\n\nThe breaker observes outcomes while allowing ordinary traffic. Opening criteria vary by implementation. Common policies use:\n\n- A specified number of consecutive failures.\n- A failure percentage within a rolling window.\n- A percentage of calls exceeding a latency threshold.\n- A combination of minimum sample size, failure rate, and slow-call rate.\n\nA rolling window may contain the most recent calls or cover a recent time interval. A minimum sample requirement helps prevent a single failure at low traffic volume from opening a breaker configured around percentages.\n\nOpen\n\nThe protected operation is not invoked for new calls admitted through the open breaker. Instead, the caller receives a recognizable rejection or takes a separate fallback path.\n\nOpening does not generally terminate calls that are already in progress. Those calls may still complete or expire under their own timeouts. Consequently, opening the breaker reduces new demand but does not necessarily release all resources immediately.\n\nThe open interval provides time for recovery. Some implementations also support manually forced-open, disabled, or monitoring-only modes.\n\nHalf-open\n\nAfter the waiting interval, the breaker permits a bounded number of trial calls. Successful trials provide evidence that calls can resume; unsuccessful trials cause the breaker to reopen.\n\nSome implementations permit only one trial, while others evaluate several calls or a short observation window. Additional incoming requests may be rejected while trials are in progress. In a demand-driven implementation, expiry of the open interval merely makes a trial eligible: a subsequent request triggers it. An active health probe is a separate mechanism."
    },
    {
      "heading": "Measurement and configuration",
      "text": "Failure classification\n\nNot every unsuccessful application response indicates an unhealthy dependency. A valid “record not found” result, for example, may be expected behavior. A request rejected because its input is invalid is also different from a server failure.\n\nThe breaker therefore needs a policy defining which outcomes:\n\n- Count as failures.\n- Count as successes.\n- Are excluded from its statistics.\n\nFor HTTP services, this policy may consider response status codes, connection errors, and timeouts. There is no universally correct mapping. A rate-limit response, for instance, may indicate a client-specific quota rather than failure of the service as a whole. Ignoring every client-error response can also conceal certain operational problems.\n\nFailure-rate thresholds\n\nA simple failure-rate policy can be expressed as\n\n\\[r = \\frac{F}{N},\\]\n\nwhere \\(F\\) is the number of outcomes classified as failures and \\(N\\) is the number of measured outcomes in the active window. The breaker opens when\n\n\\[N \\geq N_{\\min} \\quad \\text{and} \\quad r \\geq \\theta,\\]\n\nwhere \\(N_{\\min}\\) is the minimum sample size and \\(\\theta\\) is the configured failure-rate threshold. Exact comparison rules differ among implementations.\n\nShort windows react quickly but can overreact to brief fluctuations. Long windows smooth fluctuations but may delay detection or retain evidence of an outage after recovery. At very low traffic volumes, a percentage-based breaker may accumulate evidence too slowly to provide useful protection.\n\nScope and isolation\n\nA breaker’s scope determines which calls share its state and measurements. Possible scopes include a dependency, operation, destination instance, region, or tenant.\n\nA breaker shared across unrelated operations can block healthy traffic because another operation is failing. Conversely, excessively narrow scopes may provide too few samples and create large numbers of independently managed breakers.\n\nBreakers are often local to a process. Different caller instances can therefore hold different views of the same dependency. Coordinating state across callers is possible, but adds communication, consistency, and availability concerns."
    },
    {
      "heading": "Relationship to other resilience mechanisms",
      "text": "Circuit breakers form part of fault-tolerant system design, but they do not replace other controls.\n\nTimeouts\n\nA timeout bounds how long an individual call waits. A circuit breaker uses observations across calls to decide whether subsequent calls should be attempted at all.\n\nWithout suitable timeouts, a failing operation may take too long to produce the outcomes needed to trip the breaker. A timeout also does not necessarily cancel work in the remote system: a timed-out request may still finish there.\n\nRetries\n\nA retry makes another attempt after a failure, usually to handle a transient problem. A circuit breaker suppresses attempts when continued failure appears likely.\n\nTheir composition matters. If retries occur inside the breaker’s protected operation, the breaker may observe only the final result of several attempts. If each retry passes through the breaker, every attempt may contribute to its statistics. These arrangements differ in detection speed, measured failure rate, and generated load.\n\nRetries also require attention to whether repeated execution is safe. A breaker does not prevent duplicate effects when an operation succeeds remotely but its response is lost.\n\nBulkheads and concurrency limits\n\nThe bulkhead pattern isolates resources so that one failing dependency cannot consume capacity needed by others. A concurrency limit bounds the number of simultaneous operations.\n\nThese controls complement the breaker: isolation can limit damage while the breaker is still collecting evidence. Unlike a dedicated concurrency limiter, a conventional failure-rate breaker does not necessarily restrict in-flight requests while closed.\n\nRate limiting and load balancing\n\nRate limiting controls request volume according to a quota or admission policy. A breaker ordinarily bases admission on observed dependency health. Some products use “circuit breaking” more broadly to include limits on connections, pending requests, or concurrent work, so the term does not always denote the same state machine.\n\nLoad balancing distributes calls among destinations. A load balancer may remove an unhealthy instance while other instances continue receiving traffic. A broadly scoped breaker can instead reject calls to the entire dependency. These mechanisms can coexist, but their scopes affect which traffic remains available."
    },
    {
      "heading": "Fallbacks and application semantics",
      "text": "A rejected call may produce an explicit unavailable response, return cached data, omit an optional feature, or use another dependency. Such behavior is a fallback, not an inherent requirement of circuit breaking.\n\nFallbacks preserve useful behavior only when their semantics are acceptable. Cached information may be stale, omitted data may make a result incomplete, and substitute services may provide different guarantees. An apparently successful fallback must not silently imply that a required operation completed.\n\nFailures should also be measured at the correct point. If a fallback result is recorded as success for the protected dependency, it can hide the dependency’s continuing failure. Systems commonly distinguish the original call outcome, breaker rejection, and fallback outcome.\n\nFor operations involving a transaction or an external side effect, rejecting a call before dispatch is different from timing out after dispatch. In the latter case, the caller may not know whether the operation occurred. The circuit breaker does not resolve this uncertainty."
    },
    {
      "heading": "Implementation and operational concerns",
      "text": "Concurrent implementations require careful synchronization of state transitions and trial admission. Otherwise, multiple callers may all conclude that they are permitted to probe recovery, overwhelming a dependency during the half-open state. Late completions from calls admitted under an earlier state also need defined treatment.\n\nA fixed recovery interval across many caller instances can produce synchronized bursts. Randomized waiting periods and bounded trials can reduce this effect. Even then, a dependency that handles a few successful probes may fail when full traffic returns; gradual traffic restoration or adaptive admission can address a different problem from basic circuit breaking.\n\nOperational visibility commonly includes:\n\n- Current state and state-transition events.\n- Calls permitted, rejected, failed, and classified as slow.\n- Trial-call results and time spent open.\n- Fallback usage and fallback failures.\n- The policy and scope associated with each breaker.\n\nA lack of errors reaching the dependency does not itself demonstrate recovery: an open breaker may be preventing all calls. Testing therefore needs to cover recovery as well as initial failure, including intermittent faults, slow responses, concurrent trials, and the treatment of calls already in flight."
    },
    {
      "heading": "History and limitations",
      "text": "Michael T. Nygard described the circuit breaker as a software stability pattern in Release It! in 2007. Martin Fowler’s 2014 article “Circuit Breaker” further publicized the state-based pattern. Libraries such as Netflix Hystrix and later resilience libraries helped make it a familiar component of service-oriented and cloud application design.\n\nThe pattern trades immediate access to a dependency for protection against repeated unsuccessful work. It can temporarily reject calls that would have succeeded, especially after the dependency has recovered but before trial calls establish that recovery.\n\nA breaker does not repair the underlying service, guarantee end-to-end availability, or establish that all operations on a dependency are healthy. Its effectiveness depends on meaningful failure classification, suitable scope, and coordinated use of timeouts, resource isolation, and recovery controls."
    }
  ],
  "links": [
    "software-architecture",
    "distributed-computing",
    "application-programming-interface",
    "database",
    "finite-state-machine",
    "hypertext-transfer-protocol",
    "load-balancing",
    "database-transaction",
    "synchronization-computing"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}