Circuit breaker pattern in Microservice architecture

Abhinav Kumar
4 min readNov 24, 2023
Computers connected in Micro Service Architecture
Photo by Shubham Dhage on Unsplash

In this article, I will explain and share my knowledge about Circuit Breaker that is used in Micro Service Architecture to handle errors and make the system more resilient and fault tolerant. This article is to understand the concept, not a step-by-step coding implementation.

Circuit Breaker Concept

Getting inspiration from electrical circuit breakers, In Software Systems, circuit breaker objects function similarly, automatically interrupting the flow of requests when abnormalities are detected. It is situated between the caller and the callee service.
The circuit breaker ‘trips’ when the callee is unavailable. This mechanism not only prevents further damage but also allows the failing component time to recover.

In Microservice architecture, communicating through remote procedure calls and downstream API dependencies, introduces a layer of complexity where transient errors can occur due to network issues or service can fail for any reason like network outage, system overload, crash, etc.

In such a situation, it is very important to disconnect such components/services that are failing and not request further knowing that it is currently failing and allow the system to recover. A Circuit breaker component can easily disconnect downstream failed services and stop sending requests to them by opening the Circuit breaker. It also keeps watching the failed service and when it is repaired or becomes alive and ready to accept requests. The circuit breaker closed and it started sending requests to downstream services.

So, At its core, the circuit breaker pattern serves a dual purpose. Firstly, it shields a caller service from incessantly retrying a call to another service (callee) that has previously led to repeated timeouts or failures. Secondly, it acts as a sentinel, detecting when the callee service is back in action and ready to handle requests once again.

High-level architecture

Let’s understand it through a simple and easy diagram. In this example, the caller is the order service and the callee is the payment service.

This is how it looks when everything works fine and nice. 👍 And the status of the Circuit Breaker is…

--

--

Abhinav Kumar

Software Engineer @Zalando, Living in Germany, Tech enthusiast, Story Teller, Write about my learning and experiences in tech and in life.