What is CircuitBreaker?

7

I've already seen some definitions about CircuitBreaker , but I still do not understand the background how to use it and I have my doubts.

What is the best scenario to apply?

What should be aborted to be fully implemented?

Can it be used in any environment?

What frameworks can be used to make it easier to use with .NET?

    
asked by anonymous 04.08.2017 / 13:57

1 answer

3

I believe the Martin Fowler explanation is one of the easiest to understand, with illustrations and examples in code.

Imagine a system that makes several HTTP requests to a remote webservice . For an unknown reason, this webservice begins to get overwhelmed and HTTP requests take too long and give timeout .

Your system can start blocking important resources by waiting for many requests that will eventually timeout .

The purpose of Circuit Breaker is to position itself as a layer before the actual feature (the webservice in this case). In our example, it would be able to identify failures in communication with webservice (from a count of external failures, for example) and make your query fail as fast as possible internally, waste of resources.

The Circuit Breaker also has the ability to identify when the resource responds, returning to normal flow.

So, answering your questions:

  

What is the best scenario to apply?

Scenarios where early failure results in resource savings. In the above example, a system heavily dependent on a remote webservice
  

What should be aborted to be fully implemented?

I do not know if I understood the question correctly ... But, as we saw above, any costly flow can be aborted.

  

Can it be used in any environment?

Yes. But it is necessary to evaluate if the complexity that will be added will compensate in the end.

  

What frameworks can be used to make it easier to use with .NET?

The Polly library offers several policies related to resilience, including Circuit Breaker.

    
08.08.2017 / 19:19