Resilience4j
Retry ( CircuitBreaker ( RateLimiter ( TimeLimiter ( Bulkhead ( Function ) ) ) ) )
Circuit Breaker
-
Gist
For the first
minimum-number-of-calls
requests, the circuit breaker does not calculate thefailure rate
and will allow all actions to proceed.Once the
minimum-number-of-calls
is reached, if it'scount-based
, the circuit breaker will calculate thefailure-rate
(number-of-calls
/sliding-window-size
) and if it is above thefailure-rate-threshold
, it will open the circuit.When the circuit breaker is in the
open
state, all calls are rejected duringwait-duration-in-open-state
, and the circuit breaker throws aCallNotPermittedException
.Once
wait-duration-in-open-state
expires, the circuit breaker changes to thehalf-open
state and allowspermitted-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 thefailure rate
. If this newfailure rate
is above thepermitted-number-of-calls-in-half-open-state
, the circuit breaker changes back toopen
; otherwise, it changes back toclosed
. -
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
orCircuitBreakerEventsEndpoint.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.