Introduction to the Circuit Breaker Pattern

Consider that you’re running a web service that requires input and delivers it to another backend service. If the backend service is not available for some time, then what kind of fail-proof system should you implement? This is where the Circuit Breaker design pattern comes in.

Let’s think about a situation where a request goes to a middleware application and you need to call another remote backend service. If everything goes fine and smooth, the application can forward the request to the backend service and send the response back to the client. But, if the backend service was down, the request could not be completed. The next few requests from the client also try to call the backend service and fail. Here, we can use the Circuit Breaker model to manage backend errors. According to the Circuit Breaker pattern, the middleware may be in the following possible states.