3

What is the best way to add a Circuit Breaker pattern in a Microservices Architecture. Should it be on the microservice side (inside each microservice), inside an ELB or insider the Api Gateway? What would be the best design pattern?

3 Answers3

2

I think is not use in each microservice, but in your BFF (backend for frontend) who use microservice. You can find a good implementation and exemple in this book https://pragprog.com/book/mnee/release-it. Solution with API Gateway is good, see Kong https://getkong.org/ for that.

2

There are at least 3 options (illustrated below). In the general case, the circuit breaker "protects" calls to an http service. If we think this service is the microservice, the circuit breaker is never in the microservice itself.

API Gateway

In this case, you use an API gateway product that has circuit breaking support. Ambassador and Axway are examples. An alternative would be to provide circuit breaking in a BFF service that gets the calls to your backend service.

breaker in api gateway

Service mesh

In this case, you use a service mesh product that has support for circuit breaking. Istio with Envoy are an example. In this example, the insurance quote service calls the customer history service. The proxy sidecar container does the circuit breaking.

service mesh with circuit breaker

Circuit breaker lib

Here you use a library that provides circuit breaker support. Resilience4J is the one we use at work (in some Spring Boot apps that call http services).

circuit breaker lib

Your design

Which is best? It depends on your application requirements and infrastructure constraints. Things to remember:

  • Not all service interactions require circuit breaking.
  • See if a fallback mechanism (e.g., default response) can be used when the circuit is open.
  • Log/monitor circuit changes to detect problematic connections and services.
Paulo Merson
  • 13,270
  • 8
  • 79
  • 72
0

I would suggest you to delegate the circuit breaking concerns to a external library like Hystrix , rather than implementing it yourself. Hystrix exposes a lot of properties that give you full control in tuning the circuit breaking capabilities.

jith912
  • 884
  • 1
  • 9
  • 10