Introduction to Resilience4j

691 views 18 slides Nov 16, 2020
Slide 1
Slide 1 of 18
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18

About This Presentation

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.


Slide Content

Presented By:
Deepak Mehra
Lokesh Aggarwal
Introduction to
Resilience4j

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

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

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.

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.

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

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>

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.

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.

Circuit Breaker Module

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.

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).

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.

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.

Q&A

References

01
●https://resilience4j.readme.io/docs/getting-started

●https://github.com/resilience4j/resilience4j

●https://blog.knoldus.com/circuit-breaker-with-resilience4j/

●https://blog.knoldus.com/retry-with-resilience4j/

Do remember to submit
feedback!

Thank You !
Get in touch with us:
Lorem Studio, Lord Building
D4456, LA, USA