Using the Hystrix library with a reference implementation

Spring Cloud supports Netflix utilities, and Netflix has produced a library based on the circuit-breaker pattern implementation called Hystrix. In a microservice architecture, we can use the Hystrix library to prevent cascading failures, because it is very common in the microservice architecture to have several individual services hosted on different machines across a network. The microservice-based system has multiple layers of service calls.

In a microservice architecture, the failure of a lower-level service can be caused due to the cascading failure of the whole distributed system. So, Netflix Hystrix provides a way to prevent the failure of a whole system by using fallback calls and the developer can provide a fallback. Each circuit-breaker has its own threshold for failure. In Hystrix, if a particular service is called more than circuitBreaker.requestVolumeThreshold (default: 20 requests) and failure attempt percentage is more than circuitBreaker.errorThresholdPercentage (default: >50%) in a trip defined by metrics.rollingStats.timeInMilliseconds (default: 10 seconds), then Hystrix opens and a call is not made to that particular service.

Let's see how the Hystrix fallback prevents cascading failures:

Hystrix Fallback prevents cascading failures in the distributed system, which has several services, such as Service AService BService CService D, and Service E. Service Consumer calls these remote services using the API gateway, but any specific service failure can be the cause of the whole system failure. Having an open circuit stops this whole failure of the system and allows the failing services time to heal. This fallback is provided by the developer and it can be another Hystrix protected call, empty object, or some static data. The developer can also define a chain of Fallback to make a call for a business task that turns another fallback into static data or an empty business object. It is totally dependent on the business need.

Let's see how to include and configure the Hystrix in our application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.188.138