Resilience4j is a lightweight fault-tolerant framework inspired by Netflix’s Hystrix framework and designed for functional programming.

Resilience4j provides a set of decorators, including A Bulkhead, a CircuitBreaker, a RateLimiter, and a Retry, which can be combined according to your needs. Any reference to a functional interface, lambda expression, or method is enhanced, and these decorators can be superimposed.

The Resilience4j plug-in integrates CircuitBreaker, RateLimiter, and TimeLimiter in Soul Gateway

CircuitBreaker is implemented through finite state machines with three normal states: CLOSED, OPEN, and HALF_OPEN and two special states: DISABLED and FORCED_OPEN. In the CLOSE state, all requests will go through the CircuitBreaker. If the failure rate exceeds a set threshold, the CircuitBreaker will switch from CLOSED to OPEN and all requests will be rejected. After a period of time, the fuse will switch from OPEN to HALF_OPEN, and only a certain number of requests will be placed. The CircuitBreaker will recalculate the failure rate. If the failure rate exceeds the threshold, it will become OPEN, and if the failure rate is below the threshold, it will become CLOSED.

The Resilience4j data structure for recording request status is different from that of Hystrix, which uses sliding Window, while Resilience4j uses a Ring Bit Buffer.

RateLimiter is designed to prevent a sudden excessive number of requests (such as DDOS attacks or malicious web crawlers) from overloading back-end services. RateLimiter has a refresh cycle concept that limits the maximum number of requests that can be processed within a fixed refresh cycle. If the number of requests has reached the maximum in a certain flush period, all subsequent requests in that period are blocked. If a new flush period is opened within the maximum BLOCKING time, the blocked requests are processed in a new period. If a new flush cycle is not enabled within the maximum block timer, requests that exceed the block timer will be rejected outright.