top of page

Resiliance4J

  • Writer: Anand Nerurkar
    Anand Nerurkar
  • Mar 22, 2024
  • 1 min read

Updated: Jun 11, 2024

Resilience4j is a lightweight fault tolerance library designed for functional programming. Resilience4j provides higher-order functions (decorators) to enhance any functional interface, lambda expression or method reference with a Circuit Breaker, Rate Limiter, Retry or Bulkhead. You can stack more than one decorator on any functional interface, lambda expression or method reference. The advantage is that you have the choice to select the decorators you need and nothing else.


Resilience4j 2 requires Java 17.


Resiliance4J pattern

==

ree
ree

In API Gateway, the burst limit represents the target maximum number of concurrent request submissions that API Gateway will fulfill

ree

The burst limit defines the number of requests your API can handle concurrently. The rate limit defines the number of allowed requests per second. This is an implementation of the Token bucket implementation.

ree

Let us assume below scenario

ree

Service B is down or very slow to respond, in this case we can make use of resilance4j library

and implement below options

  1. Retry

  2. CircuitBreaker

  3. Rate Limiter

  4. BulkHead Circuit Breaker

ree
ree

code snippet- happy path

need to add resilance4j,aop,actuator dependency in pom.xml for serviceA,B

ree
ree

serviceB;

ree

ServiceA:

ree

Assume service A,B are working fine , in this case output would be

serviceB is called by ServiceA


Assume ServiceB is down, this is where it will cascade failure to service A , in such scenario, we will make use of ckt breaker pattern as below


serviceA:

ree

enable management endpoit as below

application.yml

==

ree

enable cktbreaker

==

ree

we have defined 10 request in a given time, 50 % threshold- minmum 5 request to be failed, then cktbreaer fallback will kick in.

ree

  1. Retry

ree

ree

Rate Limiter

ree

ree

BulkHead

ree

ree

ree

ree

ree

 
 
 

Recent Posts

See All

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
  • Facebook
  • Twitter
  • LinkedIn

©2024 by AeeroTech. Proudly created with Wix.com

bottom of page