skip to content

the target as configuration · lesson 5 of 6 · sources checked 2026-11-22

the health score and the circuit breaker for each target

This lesson builds a health score and a circuit breaker for each target, and tests each threshold with outcome sequences.

purpose

A target can refuse requests for a period. A collector that continues at the same pace adds load to the site and cost to itself, and gets nothing. A circuit breaker stops the traffic to that one target, and it starts again only on proof.

objectives

  1. Calculate a health score with a recency weight from the recent outcomes of a target.
  2. Describe the three states of a circuit breaker and the threshold of each transition.
  3. Test each threshold of a circuit breaker with outcome sequences, and refuse a default value that no test proves.
  4. State what the defender sees when a circuit breaker opens, tests, and closes.

new terms

circuit breaker
A control for one target that stops dispatch when the health score falls below a floor and tests recovery with test attempts.
half-open state
The state of a circuit breaker in which only a small number of test attempts go to the target.

how it works

The circuit breaker of a target is an instrument of the operator's own system. It protects the site and that system. When it opens, the system stops the traffic to that target. It never changes the method, the exit, or the client to continue.

the health score

The health score combines the recent outcomes of one target into one number from 0 to 1. Each attempt gives an outcome: 1 for a success and 0 for a failure. A refusal of the site is a failure.

The update rule is: new score = (1 - a) x old score + a x outcome. The weight "a" is a value from 0 to 1 that the target profile holds. A large weight lets recent outcomes count more. This is a form of recency decay.

For example, the weight is 0.3, and the score starts at 1.0. One failure gives 0.7. A second failure gives 0.49. These values are synthetic.

the three states

The circuit breaker has three states:

  1. Closed: attempts go to the target at the pace of the target profile, and each outcome updates the score.
  2. Open: no attempt goes to the target. The circuit breaker opens when the score falls below its floor, for example 0.5.
  3. Half-open: after a wait, a small number of test attempts go to the target, for example 2.

The half-open state closes the circuit breaker only on proof: each test attempt must pass. One failed test attempt opens the circuit breaker again, with a new wait. The test attempts use the same method and the same pace, or a slower pace.

After the third failed test in a row, the circuit breaker goes to a stop. A person then reviews the target. Thus a target that keeps its refusal gets no further test attempts from the system.

one circuit breaker for each target

A target that fails costs the operator money and adds pool heat. One circuit breaker for all targets lets one bad target stop the good targets. For example, target A refuses all requests, and target B accepts them. A shared circuit breaker then stops both. Thus each target has its own score and its own state.

The breaker of an earlier module stops a batch after consecutive failures. The circuit breaker of this module acts on one target and reads a score.

The circuit breaker is also an evidence-based gate: it applies and reverses by itself. A manual park does not end by itself, and a person must remember to remove it.

rules for clients of an overloaded service

My model uses four rules for clients of an overloaded service:

  • Limit the retries for each request, and do not retry a request without end.
  • Use randomized exponential backoff when you schedule retries.
  • An overloaded server returns a specific status, so that clients back off and do not retry.
  • Load test the components until they break.

The chapter "Addressing Cascading Failures" of the Google SRE book (2017) does not describe a circuit breaker Google, source 1. My model applies these rules on the side of the client. After failures, the client backs off and does not retry without end. The last rule is the reason for the tests of the next subsection.

In the sample of this page, the wait is fixed, because a fixed wait is easy to read. A random wait that becomes longer after each failed test follows the second rule.

test each threshold

A default value of a circuit breaker library is not a value for your target. Each threshold must have a test with outcome sequences. An outcome sequence is a list of the outcomes of a target at each tick, for example from a record of your own lab target. A tick is one step of the clock of the test.

Each test gives the circuit breaker one sequence and checks its end state:

sequencewhat it testscorrect end state
Noise: one failure in fiveThe floor does not open on noiseClosed, with no open
The target refuses for a periodThe circuit breaker opens, waits, and closes after the periodClosed
The target refuses from a tick onThe circuit breaker does not test without endStop for review

A floor that is too high opens on noise. A wait that is too long keeps the traffic stopped after the target recovers. The tests show both faults before the circuit breaker acts on a real target.

the two sides

automation sidedetection side
A circuit breaker stops attempts that only add pool heat and cost. The test attempts of the half-open state check recovery at a low rate. After repeated failed tests, a person reviews the target.The defender sees the traffic stop, and then return as a few test attempts. Test attempts at a fixed interval are a pattern that a defender can see. After a stop for review, the defender sees no traffic from the operator.

design decisions

optiongaincostwhen it is correct
No circuit breakerSimpleThe collector continues at full pace against a target that fails.Never for a target with a pace above a few requests
One circuit breaker for all targetsOne state for all targetsOne bad target stops the good targets.Never
One circuit breaker for each target, with a health scoreEach target stops on its own evidence.Each target must have its own thresholds and tests.Always
A large weight "a"The circuit breaker opens fast after a change.It opens more often on noise.When the outcomes of the target are stable
Stop for review after repeated failed testsNo test attempts continue against a target that keeps its refusal.A person must review the target.Always

diagram

the circuit breaker of one target, with example thresholds

The circuit breaker closes only when each test attempt passes. The values are synthetic examples.source: My model of a circuit breaker for each target

code example

The sample runs one circuit breaker on three synthetic outcome sequences. Each sequence has 40 ticks and one attempt for each tick. The rules hold example values, not values for a real target.

m51-x05-breaker.tstypescript

A circuit breaker for one target with a recency-weighted health score, half-open test attempts, a stop for review, and three tests on outcome sequences.

// Circuit breaker for one target, with a recency-weighted health score.
// All values are synthetic examples, not values for a real target.
type State = "closed" | "open" | "half-open" | "review";
const rules = { alpha: 0.3, floor: 0.5, waitTicks: 5, testAttempts: 2, maxReopens: 3 };

class TargetBreaker {
  state: State = "closed";
  score = 1;
  private openedAt = 0;
  private tests = 0;
  private reopens = 0;
  canSend(tick: number): boolean {
    if (this.state === "open" && tick - this.openedAt >= rules.waitTicks) {
      this.state = "half-open";
      this.tests = 0;
    }
    return this.state === "closed" || (this.state === "half-open" && this.tests < rules.testAttempts);
  }
  record(ok: boolean, tick: number): void {
    if (this.state === "half-open") {
      this.tests += 1;
      if (!ok) return this.open(tick, true);
      if (this.tests === rules.testAttempts) { this.state = "closed"; this.score = 0.75; this.reopens = 0; }
      return;
    }
    this.score = (1 - rules.alpha) * this.score + rules.alpha * (ok ? 1 : 0);
    if (this.score < rules.floor) this.open(tick, false);
  }
  private open(tick: number, again: boolean): void {
    if (again) this.reopens += 1;
    this.state = this.reopens >= rules.maxReopens ? "review" : "open";
    this.openedAt = tick;
  }
}

// A synthetic outcome sequence in the form of a recorded one: the result at each tick.
function test(name: string, ticks: number, okAt: (t: number) => boolean, expect: State): void {
  const b = new TargetBreaker();
  let sent = 0;
  let last: State = b.state;
  const log: string[] = [];
  for (let t = 0; t < ticks; t++) {
    if (!b.canSend(t)) continue;
    sent += 1;
    b.record(okAt(t), t);
    if (b.state !== last) { log.push(`t${t} ${b.state}`); last = b.state; }
  }
  const pass = b.state === expect ? "pass" : "FAIL";
  console.log(`${pass} ${name}: sent ${sent} of ${ticks}, end ${b.state}; ${log.join(", ") || "no change"}`);
}

test("noise, one failure in five", 40, (t) => t % 5 !== 2, "closed");
test("target refuses from t10 to t25", 40, (t) => t < 10 || t > 25, "closed");
test("target refuses from t10 on", 40, (t) => t < 10, "review");

output

One line for each test: pass or fail, the attempts sent, the end state, and the changes of state.

pass noise, one failure in five: sent 40 of 40, end closed; no change
pass target refuses from t10 to t25: sent 28 of 40, end closed; t11 open, t26 half-open, t27 closed
pass target refuses from t10 on: sent 15 of 40, end review; t11 open, t26 review

The output shows that the noise sequence never opens the circuit breaker. In the second sequence, the circuit breaker opens after two failures and closes after the period. In the third sequence, it goes to review and sends no attempt after that. The log shows only the changes of state at the end of a tick.

The noise sequence of the sample has no two failures in a row. A recorded sequence can have them, and two failures open this circuit breaker. Thus also test the floor on recorded sequences.

data

attempts sent to one lab target around a gate change, with and without a circuit breaker

status of this figure: measured by me

attempts sent to one lab target around a gate change, with and without a circuit breaker40404004040tick 140tick 150tick 160tick 170tick 180tick 190tick 200tick 210tick 220tick 230tick 240tick 250tick 260tick 270tick 280tick 290tick 300tick 310tick 320tick 330tick 340tick 350tick 360tick 370attempts per 10 ticks1. no circuit breaker2. first circuit breaker design3. selected circuit breaker

source: Lab result of this course: paced run of a circuit breaker against one own lab gate, 5 runs; date 2026-11-13; condition: Plain gate rule: each request fails on its own during the change. One invented rule on one shared lab host. Teaching values, not a model of a real target.

data table
attempts sent to one lab target around a gate change, with and without a circuit breaker
seriestickattempts per 10 ticks
no circuit breakertick 14040
no circuit breakertick 15040
no circuit breakertick 16040
no circuit breakertick 17040
no circuit breakertick 18040
no circuit breakertick 19040
no circuit breakertick 20040
no circuit breakertick 21040
no circuit breakertick 22040
no circuit breakertick 23040
no circuit breakertick 24040
no circuit breakertick 25040
no circuit breakertick 26040
no circuit breakertick 27040
no circuit breakertick 28040
no circuit breakertick 29040
no circuit breakertick 30040
no circuit breakertick 31040
no circuit breakertick 32040
no circuit breakertick 33040
no circuit breakertick 34040
no circuit breakertick 35040
no circuit breakertick 36040
no circuit breakertick 37040
first circuit breaker designtick 14040
first circuit breaker designtick 1508
first circuit breaker designtick 1600
first circuit breaker designtick 1700
first circuit breaker designtick 1800
first circuit breaker designtick 1901
first circuit breaker designtick 2000
first circuit breaker designtick 2100
first circuit breaker designtick 2200
first circuit breaker designtick 2300
first circuit breaker designtick 2400
first circuit breaker designtick 2500
first circuit breaker designtick 2600
first circuit breaker designtick 2701
first circuit breaker designtick 2800
first circuit breaker designtick 2900
first circuit breaker designtick 3000
first circuit breaker designtick 3100
first circuit breaker designtick 3200
first circuit breaker designtick 3300
first circuit breaker designtick 3400
first circuit breaker designtick 3500
first circuit breaker designtick 3600
first circuit breaker designtick 3700
selected circuit breakertick 14040
selected circuit breakertick 15012
selected circuit breakertick 1600
selected circuit breakertick 1700
selected circuit breakertick 1800
selected circuit breakertick 1901
selected circuit breakertick 2000
selected circuit breakertick 2100
selected circuit breakertick 2200
selected circuit breakertick 2301
selected circuit breakertick 2400
selected circuit breakertick 2500
selected circuit breakertick 2600
selected circuit breakertick 2701
selected circuit breakertick 2800
selected circuit breakertick 2900
selected circuit breakertick 3000
selected circuit breakertick 3101
selected circuit breakertick 3200
selected circuit breakertick 3300
selected circuit breakertick 3400
selected circuit breakertick 35028
selected circuit breakertick 36040
selected circuit breakertick 37040
Median of 5 paced runs, in bins of 10 ticks. My lab gate changes its rule at tick 150 and recovers at tick 350. The first circuit breaker design closes about 83 ticks after the recovery, which is after this window.

These are measured values from my own lab, for one invented rule of a lab gate. A lab gate is a test protection on a lab server that refuses requests by a set rule.

The chart compares the attempts sent with no circuit breaker and with two designs of a circuit breaker. With a circuit breaker, the attempts fall to almost none during the change, and they return after the recovery.

failure modes

problemcausecorrection
The circuit breaker opens on noise.The floor is too high, or the weight is too large.Test the floor on a noise sequence, and lower it until the test passes.
The traffic stays stopped after the target recovers.The wait is too long, or one test attempt that fails resets a long wait.Test the wait on a sequence with a recovery.
The circuit breaker opens and closes again and again on a target that refuses.The half-open state has no limit of failed tests.Stop for review after a set number of failed tests in a row.
One bad target stops the good targets.One circuit breaker covers all targets.Give each target its own score and state.
A threshold comes from the library default.Nobody tested it on outcome sequences.Write a test for each threshold, and keep the tests with the target profile.

check questions

  1. The weight is 0.5, and the health score is 0.8. The next attempt fails. What is the new score?

    1. 0.3
    2. 0.4
    3. 0.5
    4. 0.9
    answer

    b. 0.4

    The new score is (1 - 0.5) x 0.8 + 0.5 x 0 = 0.4.

  2. Describe the three states of a circuit breaker for one target, and the condition that starts each transition.

    sample answer

    Closed: attempts go at the pace of the target profile, and it opens when the health score falls below its floor. Open: no attempt goes to the target, and after a wait it goes to half-open. Half-open: a small number of test attempts go to the target. It closes when each test attempt passes, and it opens again when one fails. After repeated failed tests, a person reviews the target.

  3. In the half-open state, a test attempt gets a refusal of the site. What does the circuit breaker do?

    1. It opens again, with a new wait.
    2. It sends the test attempt again through a different exit.
    3. It closes, because one test attempt went to the target.
    answer

    a. It opens again, with a new wait.

    One failed test attempt opens the circuit breaker again. The circuit breaker never changes the method, the exit, or the client to continue.

  4. A circuit breaker opens on a noise sequence with one failure in five. Which change is correct?

    1. Keep the library default, because it is a known value
    2. Make the floor higher
    3. Make the floor lower, and run the noise test again until it passes
    answer

    c. Make the floor lower, and run the noise test again until it passes

    A floor that is too high opens on noise. Lower it, and test it again on the noise sequence. A library default is not a value for the target.

  5. What does the defender of a site see when a circuit breaker for that site opens, tests, and closes?

    sample answer

    The defender sees the traffic stop. After the wait, the defender sees a few test attempts. When the circuit breaker closes, the traffic returns at the pace of the target profile. Test attempts at a fixed interval are a pattern that the defender can see.

exercise

exercise Do this task on paper. The rules of a synthetic circuit breaker are:

  • weight "a": 0.4;
  • floor: 0.5;
  • start score: 1.0.

The target gives one outcome at each tick. The outcome sequence is: success, failure, failure, success.

  1. Calculate the score after each outcome.
  2. Write the tick at which the circuit breaker opens.
  3. Write what the circuit breaker does at the fourth tick.
sample answer

The answer uses the rules and the sequence of the task.

The scores are 1.0, 0.6, 0.36, and then the circuit breaker is open. After the success, the score stays 1.0. The first failure gives 0.6 x 1.0 = 0.6. The second failure gives 0.6 x 0.6 = 0.36, which is below 0.5. Thus the circuit breaker opens at the third outcome.

The fourth attempt does not go to the target, because the circuit breaker is open. No attempt goes until the wait ends. Then the half-open state sends its test attempts.

sources

  1. Addressing Cascading Failures, Google, article, read 2026-11-22
  2. My model of a health score with a recency weight and a circuit breaker for each target, 2026-11 (not public).
  3. My model of the stop for review and of tests on outcome sequences, 2026-11 (not public).