Resilience4j

Resilience4j

Retry ( CircuitBreaker ( RateLimiter ( TimeLimiter ( Bulkhead ( Function ) ) ) ) )

Circuit Breaker

  • Gist

    For the first minimum-number-of-calls requests, the circuit breaker does not calculate the failure rate and will allow all actions to proceed.

    Once the minimum-number-of-calls is reached, if it's count-based, the circuit breaker will calculate the failure-rate (number-of-calls / sliding-window-size) and if it is above the failure-rate-threshold, it will open the circuit.

    When the circuit breaker is in the open state, all calls are rejected during wait-duration-in-open-state, and the circuit breaker throws a CallNotPermittedException.

    Once wait-duration-in-open-state expires, the circuit breaker changes to the half-open state and allows permitted-number-of-calls-in-half-open-state to see if the service is still unavailable.

    In the half-open state, the circuit breaker uses another configurable ring bit buffer to evaluate the failure rate. If this new failure rate is above the permitted-number-of-calls-in-half-open-state, the circuit breaker changes back to open; otherwise, it changes back to closed.

  • The circuit breaker pattern is implemented on the consumer (caller), to avoid overwhelming a service which may be struggling to handle calls.

  • minimumNumberOfCalls should be >= permittedNumberOfCallsInHalfOpenState

  • Resources

Circuit Breaker - Debug state transition

  • Spring Boot Actuator

    Use /actuator/circuitbreakerevents or CircuitBreakerEventsEndpoint.getAllCircuitBreakerEvents() to get all circuit breaker events.

Bulkhead

The bulkhead pattern is implemented on the service (callee), to prevent a failure during the handling of a single incoming call impacting the handling of other incoming calls.