Why Circuit breaker?

Circuit breaker Prevents cascading failures across microservices and Improves user experience by failing fast instead of hanging. Supports graceful degradation with fallbacks (e.g., cached responses, safe defaults).

How Circuit breaker Works?
It cycles through three states — Closed, Open, and Half‑Open — to balance resilience with recovery.

Closed State – Requests flow normally to the downstream service, tracks metrics like error rate, timeouts, and latency.
Open State – Triggered when failures exceed the configured threshold, breaker “trips” and immediately rejects further calls.This prevents wasted retries and protects system resources.
Half‑Open State – After a cooldown period, the breaker allows limited trial requests. If these succeed → breaker resets to Closed. If they fail → breaker returns to Open for another cooldown.

What is the Default condition of Circuit breaker to move to open state?
For Resilence4j Failure Rate Threshold: 50% with a sliding window size of 100 Request. I.E. If 50 calls of last 100 request fails then circuit breaker moves to open state. Wait Duration in Open State: 60 seconds. After 60 Seconds Circuit breaker comes to half open state with 10 trial calls to test recovery before deciding to close or reopen state.

Sample config of Circuit Breaker which has sliding window of size 8 and failure call limit of 4. The CB would be OPEN state for 2 Seconds and permits 3 calls in HALFOPEN before turning to CLOSED state

resilience4j.circuitbreaker.instances.EmployeeService.registerHealthIndicator=true
resilience4j.circuitbreaker.instances.EmployeeService.slidingWindowSize=8
resilience4j.circuitbreaker.instances.EmployeeService.failureRateThreshold=4
resilience4j.circuitbreaker.instances.EmployeeService.waitDurationInOpenState=2s
resilience4j.circuitbreaker.instances.EmployeeService.permittedNumberOfCallsInHalfOpenState=3

Logs in Circuit Breaker

Count value 1
Fallback triggered due to exception: 500 Server Error on GET request for "http://localhost:8085/empmgmt/test/employees/ise": "{ "message": "500 Internal Server Error"}" Count is 1 
Count value 2
Fallback triggered due to exception: 500 Server Error on GET request for "http://localhost:8085/empmgmt/test/employees/ise": "{ "message": "500 Internal Server Error"}" Count is 2 
Count value 3
Fallback triggered due to exception: 500 Server Error on GET request for "http://localhost:8085/empmgmt/test/employees/ise": "{ "message": "500 Internal Server Error"}" Count is 3 
Count value 4
Fallback triggered due to exception: 500 Server Error on GET request for "http://localhost:8085/empmgmt/test/employees/ise": "{ "message": "500 Internal Server Error"}" Count is 4 
Count value 5
Fallback triggered due to exception: 500 Server Error on GET request for "http://localhost:8085/empmgmt/test/employees/ise": "{ "message": "500 Internal Server Error"}" Count is 5 
Count value 6
Fallback triggered due to exception: 500 Server Error on GET request for "http://localhost:8085/empmgmt/test/employees/ise": "{ "message": "500 Internal Server Error"}" Count is 6 
Count value 7
Fallback triggered due to exception: 500 Server Error on GET request for "http://localhost:8085/empmgmt/test/employees/ise": "{ "message": "500 Internal Server Error"}" Count is 7 
Count value 8
⚠️ CircuitBreaker [EmployeeService] moved to OPEN state at 2026-08-16T14:16:53.120914500+05:30[Asia/Calcutta]
Fallback triggered due to exception: 500 Server Error on GET request for "http://localhost:8085/empmgmt/test/employees/ise": "{ "message": "500 Internal Server Error"}" Count is 8 
Fallback triggered due to exception: CircuitBreaker 'EmployeeService' is OPEN and does not permit further calls Count is 9 
Fallback triggered due to exception: CircuitBreaker 'EmployeeService' is OPEN and does not permit further calls Count is 10 
Fallback triggered due to exception: CircuitBreaker 'EmployeeService' is OPEN and does not permit further calls Count is 11 
Fallback triggered due to exception: CircuitBreaker 'EmployeeService' is OPEN and does not permit further calls Count is 12 
CircuitBreaker [EmployeeService] transitioned: State transition from OPEN to HALF_OPEN
Count value 13
Downstream call took: 2009 ms
Count value 14
Downstream call took: 2006 ms
Count value 15
Downstream call took: 2008 ms
CircuitBreaker [EmployeeService] transitioned: State transition from HALF_OPEN to CLOSED
Count value 16
Downstream call took: 2012 ms
Count value 17
Downstream call took: 2008 ms
Count value 18
Downstream call took: 2016 ms
Count value 19
Downstream call took: 2013 ms
Count value 20
Downstream call took: 2013 ms

Comments are closed.