Circuit Breaker Design Pattern in 30 Seconds
Published in
2 min readNov 10, 2021
--
In a microservice architecture, remote services may be unavailable for a long time. Retrying a request won’t help in this case.
The Circuit Breaker pattern offers a solution to this problem.
The CB has three states: closed, half-open, and open.
- It starts in closed state. Your service executes all calls to the remote service.
- CB switches to open if many requests fail. Your service starts a timer and does not execute any calls to the service. It returns a default answer or throws an exception instead.
- CB switches to half-open when the timer is up. Your service executes a fraction of the calls. If all pass, it switches to “closed”. If one fails, it switches to “open” again and restarts the timer.
To summarize, the Circuit Breaker prevents the execution of calls which are doomed to fail. Look here for more information.
Learn more on Cloud Design Patterns!
- “Release It!*” contains a lot of patterns and tricks on how to design your software. Get it from Amazon: https://amzn.to/3mV76rb *
- Read the classic about design patterns from the Gang of Four. Get it from Amazon: https://amzn.to/3EYK3BU *
Disclosure: Links marked with * are Amazon affiliate links. This means that, at zero cost to you, I will earn an affiliate commission if you click through the link and finalize a purchase.