DEV Community

Cover image for Circuit Breaker: A Basic Concept
Pragya Sapkota
Pragya Sapkota

Posted on • Originally published at pragyasapkota.Medium

Circuit Breaker: A Basic Concept

A circuit breaker is a design pattern we use in system design that detects failures. It also presents a logic that prevents failure that might occur during maintenance, external system failure, or unexpected problems in the system. The concept is to enclose a protected function call in a circuit breaker which then monitors for possible failures. When the failures reach a certain threshold, the circuit breaker trips which means the remaining calls return with an error without the protected call being made. We can also have monitor alerts in case of the circuit breaker trips in any way.

Why is a circuit breaker used?

Software systems make remote calls to the software running in different processes that might lie in some other machine across a network in a faraway location. A remote call is more bound to fail and can even hang up without a response until some timeout limit is reached. This is what differentiates remote calls from in-memory calls. If we have numerous incoming calls on an unresponsive supply, you have the chance of running out of critical resources leading to cascading failures across multiple systems.

Circuit Breaker States

There are three states in circuit breaker which are individually explained below: -

Circuit Breaker States

1. Closed

Circuit Breakers are in a closed state when everything is good and normal. The request calls pass through the services normally when circuit breakers are in the closed state. However, when the failures increase and pass the threshold, the circuit breaker trips and moves to our next state — Open.

2. Open

Circuit breakers return an error without even invoking the services while in the open state. Eventually, the timeout will be specified with the help of the monitoring system while in the open state and when the certain timeout period elapses, the circuit breaker goes to the half-open state.

3. Half-open

The half-open state can go both ways. The circuit breaker can pass a limited number of requests from the service to pass through and invoke the operation. When the requests are successful, the circuit breaker goes to a closed state and when they fail, it goes to the open.

GitHub logo pragyaasapkota / System-Design-Concepts

Though the concepts of system design might be tricky, let's see them individually to their core concepts and have a better understanding.

System Design

Systems design is the process of defining elements of a system like modules, architecture, components and their interfaces and data for a system based on the specified requirements.

This is a index for the concepts of system.

If you wish to open these in a new tab, Press CTRL+click

…

I hope this article was helpful to you.

Please don’t forget to follow me!!!

Any kind of feedback or comment is welcome!!!

Thank you for your time and support!!!!

Keep Reading!! Keep Learning!!!

Top comments (0)