DEV Community

Discussion on: Fantastic Microservice and the Sorcerer's Circuit Breaker

Collapse
 
samsadsajid profile image
SajidSamsad

Hi Fuji, extremely sorry for the late reply. Was stuck! :(

Thanks for your question. A Circuit breaker can be of two types - a) counter-based b)sliding window-based.

A counter-based Circuit breaker will monitor X amount of requests. If you see the image in the article, the circuit breaker will start from the closed state. Then it will monitor the requests. If you configured that out of 10 requests if 5 fails you'll trip the circuit, then the breaker will monitor 10 requests and track how many are successful. At first, it will monitor at least 10 requests. After the 10th request, it will take the decision. From your example, say, the first 149 requests are successful. Nothing breaks. After that, your requests start to fail. If out of the next 10 requests 5 fails, the circuit breaker will trip the circuit and the state will be the open state. As I explained in the state transition paragraph in the above article, the circuit breaker will have a cool-down period until which it will wait before making another decision. You can set the cool-down period. After that, the circuit breaker will go to the half-open state as I mentioned in the article. Here, the circuit breaker will let some requests pass through and many of them will be not. And in the half-open state, if the circuit breaker sees that out of the 10 requests that it passed through 5 failed then it will again switch to the open state. Otherwise, it will switch to the closed state. The whole 151 requests will not be used to trip the circuit.

Hope it helps. If you have questions, please do comment. I liked your question. And again, sorry for the late response.

Thread Thread
 
fuji1405116 profile image
Fuji • Edited

yeah, so the counter is resetting (starting to monitor) after every success call as I started counting after the first failure? but then after 3 consecutive fails and then 1 success call will again reset the state -_- or the concept is I just monitor (without resetting) consecutive 10 requests then reset and again monitor 10 consecutive requests and again?
and as you said when after failing over 50% request handling (the first 149 was good then consecutive 6 fails) during the cool down period or half-open state, is the server serving that capable 149 requests and not making another call (hold) within short time or it is now not handling any requests? (um confused here) as from our trivial knowledge we know circuit breaker as breaking the full circuit while overload but here we can code to serve the capable 149 request and hold for any new requst (cool down)?
Thanx a lot for the reply <3