Resilience4j is an easy-to-use fault tolerance library inspired by
Netflix Hystrix, but designed for Java 8 and functional programming.
Resilience4j is a lightweight fault tolerance library inspired by Netflix Hystrix, but designed for Java 8 and functional programming.
2. Lack of etiquette and manners is a huge turn off.
KnolX Etiquettes
Punctuality
Respect Knolx session timings, you
are requested not to join sessions
after a 5 minutes threshold post
the session start time.
Feedback
Make sure to submit a constructive
feedback for all sessions as it is
very helpful for the presenter.
Mute
Please keep your window on mute
Avoid Disturbance
Avoid leaving your window
unmuted after asking a question
3. Agenda
● What is Resilience4j?
● Why Resilience4j?
● How many modules are there in Resilience4j?
● How to use Resilience4j in your projects?
● Circuit Breaker
● Retry
● Q&A
4. What is Resilience4j?
● Resilience4j is an easy-to-use fault tolerance library inspired by
Netflix Hystrix, but designed for Java 8 and functional programming.
● Resilience4j is a lightweight fault tolerance library inspired by Netflix Hystrix, but
designed for Java 8 and functional programming.
● In Resilience4j you don’t have to go all-in, you can pick what you need.
5. Why Resilience4j?
● This library is capable of handling the asynchronous calls
● Resilience4j is designed for Java8 and functional programming
● Resilience4j enables the resilience in complex distributed systems where failure
might take place
● Resilience4j is lightweight because it only uses Vavr, which does not have any
other external library dependencies.
6. Modules in Resilience4j?
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
7. How to use Resilience4j in your projects?
You can simply use the following dependency in your maven project and get
started with the Resilience4j
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot2</artifactId>
<version>1.5.0</version>
</dependency>
8. Circuit Breaker Module
● The circuit breaker is essentially a pattern that helps to prevent cascading
failures in a system.
● The circuit breaker pattern allows you to build a fault-tolerant and resilient
system that can survive gracefully when key services are either unavailable or
have high latency.
● Circuit breaker pattern is generally used in microservices architecture where
there are multiple services involved but it can be used otherwise as well.
9. Circuit Breaker Module
The circuit breaker has the following 3 states
Closed – Closed is when everything is normal, in the beginning, it will be in the
closed state and if failures exceed the threshold value decided at the time of
creating circuit breaker, the circuit will trip and go into an open state.
Open – Open is the state when the calls start to fail without any latency i.e calls
will start to fail fast without even executing the function calls.
Half-open – In half-open state what will happen is, the very first call will not fail
fast and all other calls will fail fast just as in the open state. If the first call
succeeds then the circuit will go in the closed state again and otherwise, it will go
into the open state again waiting for the reset timeout.
11. Retry Module
● There can be scenarios when there are intermittent network connectivity errors
causing your service to be unavailable.
● These issues are generally self-correcting and if you retry the operation after a
small delay its most probably going to succeed.
● Retry pattern help to resolve transient failures in distributed architecture by
automatically hit the target resource again after some specific time.
12. When to use Retry
The faults are expected to be short lived, and repeating request that failed
previously could succeed on a subsequent attempt.
● Calling an HTTP service from another REST endpoint.
● Calling a web service.
● No or slow responses due to a large number of requests towards the
resource(database or service).
13. Important points while using Retry
● When fault is likely to be long lasting, should not use Retry.
● We should keep the number of retries b/w 3 and 5(not more than 5).
● We should take care of the idempotency principle.
14. How does Retry works?
● User invoke operation on hosted service. Request fails and service host responds
with 500 internal server error.
● Application waits for a short interval of time and tries again. The request still fails
with HTTP response code 500.
● Application waits for a short interval of time and tries again.. The request
succeeds with 200 OK response.