December 06, 2019

Part 16: Microservices (Implementing Circuit Breaker and Bulkhead patterns using Resilience4j)

Circuit Breaker Pattern
Circuit breaker is a resilience pattern. This pattern help prevent cascading failures. A circuit breaker is used to isolate a faulty service, it wraps a fragile function call (or an integration point with an external service) in a special (circuit breaker) object, which monitors for failures. Once the failures reach a certain threshold, the circuit breaker trips, and all further calls to the circuit breaker return with an error, without the protected call being made at all.

ALSO READ: Part 6: Microservices (Fault Tolerance, Resilience, Circuit Breaker Pattern)

Bulkhead Pattern
Bulkhead pattern is used to isolate elements and in our case microservices into connection pools so that if a resource fails then it only affects that connection pool. It is used to avoid faults in one part of a system to take the entire system down.

ALSO READ: Part 9: Microservices (Bulkhead Pattern using Hystrix)

Hystrix, which was originally created by Netflix implements both circuit breaker and bulkhead patterns, so we don't have to implement it. The sad part is Hystrix its no longer under active development now, it has been maintained right now.

In November 2018 when Netflix announced that they are putting this project into maintenance mode, it prompted Spring Cloud to announce the same. Since then, no further enhancements are happening in this Netflix library. In SpringOne 2019, Spring announced that Hystrix Dashboard will be removed from Spring Cloud 3.1 version which makes it officially dead.

The happy part is that there is another way by which we can easily implement both these Resilience patterns. Resilience4j library, which inspired by Hystrix offers a much more convenient APIs and a number of other features like Rate Limiter (block too frequent requests).

Resiliene4j Modules
Resilience4j has got several core modules. We can add these modules seprately in our project, if you don’t have to go for all the modules. In case you want all the modules you can simply go for 'resilience4j all'. Resilience4j has the following 6 core modules.

  • resilience4j-circuitbreaker: Circuit breaking
  • resilience4j-ratelimiter: Rate limiting
  • resilience4j-bulkhead: Bulkheading
  • resilience4j-retry: Automatic retrying (sync and async)
  • resilience4j-cache: Result caching
  • resilience4j-timelimiter: Timeout handling

-K Himaanshu Shuklaa..

No comments:

Post a Comment