Walk through the states of a circuit breaker and the parameters you would tune.
Sketch your own answer first, then compare it with the one below.
A strong answer
A breaker has three states. Closed is normal: requests go through and the breaker records outcomes. When too many recent attempts have failed, it opens. In the open state, requests fail immediately without being sent. After a cool-down it becomes half-open, and lets a few probe requests through. If they succeed, it closes. If one fails, it opens again for another cool-down.
The parameters are the failure threshold, as a rate or a count, the minimum number of requests before it decides, the window it looks at, the length of the cool-down, and the number of probes. What counts as a failure also matters: timeouts and 5xx errors usually do, client errors do not.
The breaker protects the dependency from load, and protects the caller from waiting on a service that will not answer. It fails fast, so threads and connections are freed.
The costs are real. Open means failing requests on purpose, so it needs a fallback or a clear error. Too sensitive and a blip opens it. Too slow and the damage is done. A breaker in every process trips and probes on its own schedule.
Sources
- Martin Fowler (2014). Circuit Breaker.
- Michael T. Nygard (2018). Release It!, Second Edition.