Making systems more resilient (1) - Circuit Breaker
Circuit Breaker has an interesting name that comes from the analogy found in the physical electrical world. Every decent electrician recognizes that playing with electricity is dangerous and that she must install security mechanisms to protect the rest of the electrical network if one device breaks down. What do electricians do? They install fuses. If a device (say toaster!) breaks down and produces short circuit, strong electric current will flow through the network resulting in damage, overheating and possibly fire. Unless there is a fuse in the network! If there is strong electric current flowing, the fuse will melt down or otherwise break the electrical circuit, stop the current and save the rest of the network.
Circuit Breaker mechanisms in software are very much like electrical fuses in the real world. Suppose one of your services is calling another:
When Circuit Breaker detects that called service is down, it can do various things. It could return a meaningful error to the caller but it could also return a “good enough” result that would provide some value for the user. Let’s take an example of a banking application which shows account balance fetched via separate service. If that service goes down, Circuit Breaker could return last known balance from the cache. Yes, it is clear that yesterday’s balance might not be valid today, but accompanied with a proper message it’s better than nothing. “Dear customer, we’re experiencing some trouble getting your balance at the moment, but your balance 3 hours ago was €234.55” beats “Your balance is €null” anytime. Of course, what Circuit Breaker can return needs to be carefully thought through from business perspective.
Circuit Breakers are really cool. In Part 2 of this series, we will lift the hood and show concrete Circuit Breaker implementation.
— Photo by rawpixel.com from Pexels.
Get in touch
Want to hear more about our services and projects? Feel free to contact us.Contact us