Thursday, 18 December 2014

Circuit Breaker - 2

We saw how circuit breakers (CBs) work in electronics and power engineering, and mentioned that there are many more usage examples in other industries too. Now let us see how we can get the benefit of using a CB in software design.

Using circuit breaker in software design
Look at this diagram, at the top we have two components, they can be two software modules in a single binary or two separate binaries in a single machine communicating to each other through shared memory, a pipe, ... or they may even be two separate binaries working in a network. In any of these cases component 1 simply sends some data packets to component 2, they may also have some feedback of how things are going on the other side too.

The idea is of using a CB is exactly like what we have in other industries, separating components if something wrong happens to the flow of data, one of the components or ... Depending on what situations or conditions the CB separates two component, we can simulate the behavior of a fuse, circuit breaker, IDE circuit breaker and ... (in my point of view naming doesn't matter that much) 


We can use CB idea either as a standalone component or an internal part of these components like what we see in the middle and the bottom diagram, now let us see how this CB works. Here we describe some of the many ways a CB can work:
  • Preprogrammed CB: You program the CB before using it as a standalone component, and by programming I mean just configuring it on what condition it should isolate the two components. For example, You may want the CB breaks when the data flow throughput goes above 1000 data packets per second. In this case, all the CB should do is to check for the input rate and if see it is more than CB breaks the path (This is something like what a fuse does in an electrical circuit). You may config the CB to start working after a period of time too. 
  • Feedback Provided CB: You may design your CB in a way that allows it to have some feedback from the side components too. In this case, the CB can make complex decisions too. Like what we had in IDE circuit breakers. Now the CB know enough from both components on what they are doing and in what conditions they currently are. It also can compare the info from both sides to make a decision on what to do.
  • Internal CB: In this case this part of side components code should control the situation - for example, the flow rate - and if sees it is abnormal, stops receiving or sending any more data. Note that in any of these there examples we can let the CB completely isolates the two components or just lets some specific data rate passes through.
I remind this again when a software is too large and complex or works in a big ecosystem, you need to have such data current control systems to make sure your component works and can continue working - stable - as much as possible. There are some more benefits for these systems (like CB) they don't let the whole system goes down if a part gets into trouble. (Think about having a whole city power outage because you in your home had an electrical short circuit!!!) 

No comments:

Post a comment