Search code examples
microservicescircuit-breaker

Circuit breaker as stand alone service


I am building microservices architecture for the first time and despite I have read a lot of articles I am still confused how to correctly implement circuit breaker.

Let's suppose that I have several microservices that call each other. So I implemented circuit breaker into each of them as an request interceptor and it works. But I dont like it.

Firstly each service now needs to hit the fail threshold separately before the breaker open. Secondly I write the same functionality for each service over and over again.

So my first thought was to create circuit breaker as stand alone service but I can not find any pattern describing such a functionality. How it would works? Every service before making request calls circuit breaker service firs if target circuit is closed. If so it sends request and when request is finished then reports back to circuit breaker service whether the request was successful or failed?

Or how should be circuit breaker correctly put into microservices architecture?


Solution

  • When you are talking about real micro services architecture circuit breaking is a cross-cutting-concern

    You should not implement it by yourself. First of all I should say please be careful of creating spaghetti between your micro services, It's too dangerous and anti-pattern. Although its an anti-pattern I highly recommend you to use cloud native platforms to deploy your micro-services like Kubernetes or mabye Docker. There are lots of useful tools like Envoy-implemented side-cars, service mesh implementations using Istio (not recommended), Consul and other Hashicorp products. You can improve your service discovery, observability, monitoring, circuit-breaking, logging, side-micro-service-communication and other useful concepts using cloud native tools.

    Hint: I highly recommend you to use grpc instead of http requests between your services (To reduce latency based on http3 and tcp connections)