Overview of the circuit breaker in Hystrix

Libraries provided by Netflix, usually look simple, but after a deep dive, you will realize this stuff is pretty complicated. In this article, I want to explain behavior and usage of the circuit-breaker pattern being a part of the Hystrix.

Following the Wikipedia definition "Circuit breaker is used to detect failures and encapsulates logic of preventing a failure to reoccur constantly (during maintenance, temporary external system failure or unexpected system difficulties)." What does it mean?
For example, let's consider the circuit as a connection between two services. It operates normally (aka stays closed) when the connection is stable, and the target service is healthy. We can execute our requests (assume 100 per second) without any problems.
But when our target service is down (what we know after a few unsuccessful tries), it no longer makes any sense to try 100 times per second. So we open our circuit and serve responses from a predefined fallback, as we know that the service won't reply.

How is it implemented in the Hystrix?

We start with the closed circuit. All requests are processed, and Hystrix is gathering metrics. Metric includes information about a number of processed requests, execution time and a finish status. As long as everything is up and running, and there are no network issues the circuit breaker (CB) stays closed.
If we execute less than a minimum number of request (circuitBreakerRequestVolumeThreshold property, default to 20) in a given time window (metricsRollingStatisticalWindowInMilliseconds property, default to 10 seconds), there won't be any decision to change the status. If we fulfill the minimum threshold requirement and more than a given number of requests have failed (circuitBreakerErrorThresholdPercentage, default to 50%), Hystrix will decide to open the CB. Now when we try to execute the next request, it will be redirected straight to the fallback.

But how do we know when the service will be back online? Hystrix allows one request per some time, called the 'sleep window` (circuitBreakerSleepWindowInMilliseconds, default to 5 seconds) to execute normally. Launching such request changes the CB status to half open. Now based on the result of this request, CB status will be changed to:
- closed, if the request finished successfully,
- open, if the request failed.

Now, to be fully correct, I need to clarify one thing. In fact, for Hystrix there is no such thing like "request." It operates on "commands," which of course can be implemented to execute a RESTful request.

Usage

But when I decide to use Hystrix in my application, does it mean there will be just one circuit breaker? No! There are usually more instances, and the one which will be used for a given command is determined by a key being the name of the command. So is there any naming convention? Not really, because it depends on what we exactly want to achieve - how to divide our commands.

If you're for example afraid that the particular REST endpoint (regardless the physical host we hit) can fail - let's say "GET /users," it's a good idea to name the command "getUsers". Then all calls to userService1, userService2, ..., userServiceN will be protected by the same circuit breaker.

When more important is which host are you talking to (because e.g. we do use sticky-session client-side load-balancing) the above name won't help. Then it's better to name the command equally to the host name, so "userService1", "userService2", etc. Then outage of the one instance won't impact the other calls. There is just one tiny problem - if you want to specify any properties of the command (like a timeout) it can be done on a command name level. So all requests to the userService1 must have the same configuration. Often we have endpoints which take longer to finish, so it looks like a serious limitation.

There is the third possibility, to merge both approaches and use "userService1#getUsers" name. It solves the different settings issue, but it will be less effective than the second solution, as all circuits we have for a given host needs to be closed/opened independently.

The best solution would be to be able to use a custom key for a circuit breaker resolution, however, it's unfortunately still not possible.

Comments

newvalue said…
Thanks for your detail explanation.
Unknown said…
Thanks for sharing this informative article here about the circuit breaker. A good electric circuit breaker is very useful to protect an electrical circuit from damage. If you are looking to buy Square d circuit breaker, visit mdwindustrialsupply.com
Malcom Marshall said…
Thanks for sharing this informative article here about the circuit breaker. This information is really useful. Visit Skartec
Maria said…
In the evening it happens that sidish is boring in the evening and you don’t know what to do with your desire to chevoto gamble, cool. Found this site swell top 10 online casinos now sitting here all day. Money withdraw easily, cool design. I like everything
It looked like a phenomenal treat yelling out to me to eat it. This is worthy article.
SAP training in Kolkata
Best SAP training in Kolkata
SAP training institute in Kolkata
vijay said…
This is one of the best post i have read in months, its really great and inspiring, i will really like to read more form you and will like to share with others as well, keep writing more.
Salesforce Training in Chennai

Salesforce Online Training in Chennai

Salesforce Training in Bangalore

Salesforce Training in Hyderabad

Salesforce training in ameerpet

Salesforce Training in Pune

Salesforce Online Training

Salesforce Training

vijay said…
Very interesting blog. Many blogs I see these days do not really provide anything that attracts others, but believe me the way you interact is literally awesome.You can also check my articles as well.
Salesforce Training in Chennai

Salesforce Online Training in Chennai

Salesforce Training in Bangalore

Salesforce Training in Hyderabad

Salesforce training in ameerpet

Salesforce Training in Pune

Salesforce Online Training

Salesforce Training


The information you have shared here is really informative. I got some great knowledge about circuit breaker from this post. Keep Posting. test and tag services sydney
christianharvey said…
I am very grateful that I found some helpful content about circuit breaker in this post. After reading it , I think that you have good knowledge. Thanks for posting it. Keep it up. electrical test and tag
Yayukata said…
A very delightful article that you have shared here.japanese windbreaker Your blog is a valuable and engaging article for us, and also I will share it with my companions who need this info. Thankful to you for sharing an article like this.
servicecorrp said…
I generally want quality content and this thing I found in your article. It is beneficial and significant for us. Keep sharing these kinds of articles, Thank you.Test & Tag Adelaide
christianharvey said…
You have done a good job by publishing this article about electrical testing. I appreciate your efforts which you have put into this article, It is a beneficial article for us. Thanks for sharing such informative thoughts. Test and tag cost
senthilpraveen said…
Such a nice blog with the reference links. Thanks for sharing with others.
Selenium Course In Chennai
Selenium Training Online
Selenium Course In Bangalore
lakshmanan a said…
Superb blog post! And this blog clearly explain about for useful information. I would Thanks for sharing this wonderful content. Its very useful to us. Keep it up!
php developer interview questions
php technical interview questions
php interview questions and answers for experienced
php interview questions and answers for freshers
php programming interview questions
Arnold DK said…
i was unaware about ctk breaker .your article is well explained in this field. also check out for this link Kinemaster Lite
Edison hope said…
Very interesting blog. A lot of the blogs I visit nowadays don't really provide anything that I'm interested in, but I'm definitely interested in this one Turkish e Visa is an electronic visa Turkey that allows entry into Turkey. Once available, eligible foreign will be able to complete the online application process without visiting an embassy or consulate.
Tom said…
Nice article thank you for this. Check the Kenya visa requirements before you apply for the Kenya visa through online visa application. The e visa application offers the fast visa services and check kenya entry requirements.
Deniel Alex said…
This is a topic that’s near to my heart… Many thanks! Where are your contact details though? emergency visa application India, You can get an India visa in 5 to 10 minutes. In 3 simple steps you can apply your Indian eVisa, fill the form with correct details and submit all the documents and make the payment.
A very delightful article that you have shared here.Initial Verification and Periodic Test Inspection in Medway Your blog is a valuable and engaging article for us, and also I will share it with my companions who need this info. Thankful to you for sharing an article like this.
Vuta Electrical said…
I admire this article for the well-researched content and excellent wording. Read more info about Electrician in Springfield. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much.
milka said…
Great post. keep sharing such a worthy information.
Digital Marketing Course in Chennai
milka said…
Great post. keep sharing such a worthy information.
AWS Training in Chennai

milka said…
Great post. keep sharing such a worthy information.
CCNA Course in Chennai

milka said…
Great post. keep sharing such a worthy information.
Best Python Training Institute in Chennai

milka said…
Great post. keep sharing such a worthy information.
IELTS Coaching in Chennai
Anonymous said…
You can find out the specific poker hand rankings for each video poker sport by taking a look at} its paytable, which we’ll clarify in a second. Most new players keep a single jack or higher rather than a low pair, and it is true that keeping that 코인카지노 one excessive card will lead to more frequent winning palms. But most of those will be 1-for-1 payoffs for a pair of jacks or higher.

Popular posts from this blog

Understanding Spring Web Initialization

Do we really still need a 32-bit JVM?