English 中文(简体)
Circuit Breaker
  • 时间:2024-11-05

Microservices Design Patterns - Circuit Breaker


Previous Page Next Page  

Problem Statement

Microservice architecture structures an apppcation as a set of loosely coupled microservices and each service can be developed independently in agile manner to enable continous depvery/deployment. These services often interacts with other microservices. Now there is always a possibipty that a service is overloaded or unavailable. In such a case the caller service will also wait. If multiple services are getting blocked then it will hamper the performance and can cascade the impact on overall apppcation.

Now, how to prevent a service failure or network failure from cascading to other services. If one service is down then it should not be given further requests.

Solution

We can use circuit breaker pattern where a proxy service acts as a circuit breaker. Each service should be invoked through proxy service. A proxy service maintains a timeout and failures count. In case of consecutive failures crosses the threshold failures count then proxy service trips the circuit breaker and starts a timeout period. During this timeout period, all requests will failed. Once this timeout period is over, proxy service allows a given pmited number of test requests to pass to provider service. If requests succeed the proxy service resumes the operations otherwise, it agains trips the circuit breaker and starts a timeout period and no requests will be entertained during that period.

Advertisements