17

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

Nafaz M N M
  • 1,558
  • 2
  • 27
  • 41

2 Answers2

24

These are fundamentally different patterns.

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

The bulkhead pattern is implemented on the service, 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 increase the resilience of a distributed system.

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

tom redfern
  • 30,562
  • 14
  • 91
  • 126
11

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.

Dina Bogdan
  • 4,345
  • 5
  • 27
  • 56