Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a circuit breaker and a bulkhead pattern?

Can we use both together in Spring Boot during the development of microservice?

like image 857
NafazBenzema Avatar asked Apr 02 '20 11:04

NafazBenzema


People also ask

What is bulkhead in circuit breaker?

The Bulkhead pattern is a type of application design that is tolerant of failure. In a bulkhead architecture, elements of an application are isolated into pools so that if one fails, the others will continue to function.

What are the 2 types of circuit breakers?

Standard circuit breakers come in two varieties: single-pole breakers and double-pole breakers. These are simpler breakers that monitor the cadence of electricity as it circulates an indoor space.

What does pattern breaker mean?

The Circuit Breaker pattern prevents an application from performing an operation that is likely to fail. An application can combine these two patterns by using the Retry pattern to invoke an operation through a circuit breaker.


2 Answers

These are fundamentally different patterns.

A circuit breaker pattern is implemented on the caller side, to prevent overwhelming a service which may be struggling to handle calls. A sample implementation in Spring can be found here.

A bulkhead pattern is implemented on the service side, to prevent a failure during the handling of a single incoming call impacting the handling of other incoming calls. A sample implementation in Spring can be found here.

The only thing these patters have in common, is that they are both designed to improve the resilience of a distributed system.

So, while you can certainly use them together in the same service, you must understand that they are not related to each other, as one is concerned with making calls and the other is concerned with handling calls.

like image 59
tom redfern Avatar answered Oct 25 '22 20:10

tom redfern


Yes, they can be used together, but it's not always necessary.

  1. As @tom redfern said, circuit breaker is implemented on the caller side. So, if you are sending request to another service, you should wrap those requests into a circuit breaker specific to that service. Keep in mind that every other third party system or service should have it's own circuit breaker. Otherwise, the unavailability of one system will impact the requests that you are sending to the other by opening the circuit breaker.

More informations about circuit breaker can be found here: https://learn.microsoft.com/en-us/azure/architecture/patterns/circuit-breaker

  1. Also, @tom redfern is right again in the case of bulkheading, this is a pattern which is implemented in the service that is called. So, if you are reacting to external requests by spanning other multiple requests or worloads, you should avoid doing all those worloads into a single unit (thread). Instead, separate the worloads into pieces (thread pools) for each request that you have spanned.

More information about bulkheading can be found here: https://learn.microsoft.com/en-us/azure/architecture/patterns/bulkhead

Your question was if it's possible to use both these patterns in the same microservice. The answer is: yes, you can and very often the situation implies this.

like image 28
Dina Bogdan Avatar answered Oct 25 '22 21:10

Dina Bogdan