Circuit Breaker Pattern

The Circuit Breaker pattern is one in which an intermediary service is placed between a caller and a target. The purpose of the intermediary service is to observe conditions in the target. Should hazard occur, the circuit breaker process reroutes traffic to another service that has the logic to mitigate the hazardous condition.

Figure 1: The Circuit Breaker Architecture pattern.

Analogically, the pattern is similar to a physical circuit breaker for electric lines. When an electric line becomes overloaded and runs the risk of overheating and causing a fire, the circuit breaker trips and stops electricity from flowing through the circuit’s wire.

Pros

  • Using a circuit breaker to respond to the onset of a hazardous condition in a fault tolerant manner is an excellent way to prevent accidents before they happen. 
  • Provides a good way to make systems fault-tolerant at a fine level of activity.

Cons

  • Testing can be harder than it appears. More is required than simply having the circuit breaker close down access to a particular service. A variety of failure responses need to be in force and these responses need to be tested.
  • Circuits are difficult to do as a one-off. They require an infrastructure management technology such as a service mesh that can manage the switching on and off.

Conclusion

In terms of addressing failure at a general application level, relying on each process in the system to accommodate failure is a time-consuming undertaking. Making updates at the process level is even more laborious. Using the Circuit Breaker pattern in conjunction with a system management technology such as a service mesh allows software architects to take a global approach to creating fail-safe systems.

Leave a Comment

Your email address will not be published. Required fields are marked *