What is Circuit Breaker?
Circuit Breaker is a pattern to monitor the failures and it keeps the count of failure, after reaching the threshold of failure. it stops sending requests to the external server till timeout.
State of the Circuit Breaker
Circuit Breaker has three states:
Closed: It is a normal state. Every request going through the services.
Open: When shit started, If External server is started to failing the requests then the circuit breaker comes in open state once the failure threshold reached. No requests go to the external services. Simply fail fast.
Half-Open: After the timeout, the Circuit breaker went to the half-open state, now requests go to the services and if any requests failed then still state moved to open state otherwise reset to the closed state. Simply automatic healing.
How it benefits?
It prevents cascading failures and keeps the system responsive.
- We can set a default response until Circuit Breaker is in open state.
- Other functionality & API should work.
- If we know the other system is down then no need to send requests & wait for a response.
- Automatically check the system status in the half-open state.
- Martin Flower blog: https://martinfowler.com/bliki/CircuitBreaker.html
- Netflix blog: https://medium.com/netflix-techblog/making-the-netflix-api-more-resilient-a8ec62159c2d
- Netflix Open Source Hystrix: https://github.com/Netflix/Hystrix/