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

==


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

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.

Let us assume below scenario


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


code snippet- happy path

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

serviceB;


ServiceA:


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:


enable management endpoit as below

application.yml

==


enable cktbreaker

==


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


  1. Retry



Rate Limiter



BulkHead






 
 
 

Recent Posts

See All
Best Chunking Practices

1. Chunk by Semantic Boundaries (NOT fixed size only) Split by sections, headings, paragraphs , or logical units. Avoid cutting a sentence or concept in half. Works best with docs, tech specs, policie

 
 
 
Future State Architecture

USE CASE: LARGE RETAIL BANK – DIGITAL CHANNEL MODERNIZATION 🔹 Business Context A large retail bank wants to “modernize” its digital channels (internet banking + mobile apps). Constraints: Heavy regul

 
 
 

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