Circuit breaker pattern algorithm

Ragavendra B.N.

Ragavendra B.N.
This post is about trying to implement the circuit breaker pattern in your program. Analgous to the electrical circuit breaker in the house,the circuit breaker can be built and customized to improve system resilience.
Basic steps -
- Count the error API's say for a speicific API and store it.
- Once the count exceeds the limit say 10, move the client system to the Half - open state and start the timer.
- Set the timer to about say 15 seconds.
- After the timer expires, try the call(s) again slowly.
- If the calls fail, move the system to the Open state.
- Otherwise, the specific API can be put into Closed state again.
State definition -
Open - Client is not sending any calls (may be specific API). Half - Open - System in probe mode after failures to check resilience. Closed - System performing as normal and no issues from the server.