A service calls a database cluster with 12 replicas. One replica starts timing out on every request. Should the circuit breaker wrap the whole cluster or each replica?
Sketch your own answer first, then compare it with the one below.
A strong answer
Each replica, or each host, if you can tell them apart. A breaker around the whole cluster sees 1 failure in 12 attempts, about 8 percent. That is below any sensible threshold, so it stays closed. Meanwhile one request in twelve goes to the bad replica and waits out its timeout. Callers see a steady, avoidable tail of errors.
A breaker per replica sees 100 percent failures from the bad host and opens only that breaker. Traffic goes to the other 11, and the bad host receives a probe now and then until it recovers. This is often called outlier detection or ejection.
Limits apply. Do not eject too many at once: if a shared problem makes all 12 look bad, ejecting everything is an outage. Cap the share that can be out, say half. Make sure the remaining replicas can absorb the load, since 11 now carry what 12 did, about 9 percent more each.
A breaker around the whole cluster still has a job. It catches the case where everything is failing, and stops the callers from piling up on it. The two work at different levels.
Sources
- Martin Fowler (2014). Circuit Breaker.
- Michael T. Nygard (2018). Release It!, Second Edition.