{"id":5800,"date":"2026-08-16T07:16:15","date_gmt":"2026-08-16T07:16:15","guid":{"rendered":"https:\/\/codethataint.com\/blog\/?p=5800"},"modified":"2026-08-16T09:04:44","modified_gmt":"2026-08-16T09:04:44","slug":"microservices-patterns-resilence-and-fault-tolerance-circuit-breaker","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/microservices-patterns-resilence-and-fault-tolerance-circuit-breaker\/","title":{"rendered":"Microservices Patterns &#8211; Resilence and Fault Tolerance &#8211; Circuit Breaker"},"content":{"rendered":"<p><strong class=\"ctaHeader3\">Why Circuit breaker?<\/strong><\/p>\n<p>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).<\/p>\n<p><strong class=\"ctaHeader3\">How Circuit breaker Works?<\/strong><br \/>\nIt cycles through three states \u2014 Closed, Open, and Half\u2011Open \u2014 to balance resilience with recovery. <\/p>\n<p><strong>Closed State<\/strong> &#8211; Requests flow normally to the downstream service, tracks metrics like error rate, timeouts, and latency.<br \/>\n<strong>Open State<\/strong> &#8211; Triggered when failures exceed the configured threshold, breaker \u201ctrips\u201d and immediately rejects further calls.This prevents wasted retries and protects system resources.<br \/>\n<strong>Half\u2011Open State<\/strong> &#8211; After a cooldown period, the breaker allows limited trial requests. If these succeed \u2192 breaker resets to Closed. If they fail \u2192 breaker returns to Open for another cooldown.<\/p>\n<p><strong class=\"ctaHeader3\">What is the Default condition of  Circuit breaker to move to open state?<\/strong><br \/>\nFor Resilence4j Failure Rate Threshold: <strong>50% <\/strong> 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.<\/p>\n<p><strong class=\"ctaHeader3\">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<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\nresilience4j.circuitbreaker.instances.EmployeeService.registerHealthIndicator=true\r\nresilience4j.circuitbreaker.instances.EmployeeService.slidingWindowSize=8\r\nresilience4j.circuitbreaker.instances.EmployeeService.failureRateThreshold=4\r\nresilience4j.circuitbreaker.instances.EmployeeService.waitDurationInOpenState=2s\r\nresilience4j.circuitbreaker.instances.EmployeeService.permittedNumberOfCallsInHalfOpenState=3\r\n<\/pre>\n<p><strong>Logs in Circuit Breaker<\/strong><\/p>\n<pre>\r\nCount value 1\r\nFallback triggered due to exception: 500 Server Error on GET request for \"http:\/\/localhost:8085\/empmgmt\/test\/employees\/ise\": \"{<EOL><EOL> \"message\": \"500 Internal Server Error\"<EOL><EOL>}<EOL><EOL>\" Count is 1 \r\nCount value 2\r\nFallback triggered due to exception: 500 Server Error on GET request for \"http:\/\/localhost:8085\/empmgmt\/test\/employees\/ise\": \"{<EOL><EOL> \"message\": \"500 Internal Server Error\"<EOL><EOL>}<EOL><EOL>\" Count is 2 \r\nCount value 3\r\nFallback triggered due to exception: 500 Server Error on GET request for \"http:\/\/localhost:8085\/empmgmt\/test\/employees\/ise\": \"{<EOL><EOL> \"message\": \"500 Internal Server Error\"<EOL><EOL>}<EOL><EOL>\" Count is 3 \r\nCount value 4\r\nFallback triggered due to exception: 500 Server Error on GET request for \"http:\/\/localhost:8085\/empmgmt\/test\/employees\/ise\": \"{<EOL><EOL> \"message\": \"500 Internal Server Error\"<EOL><EOL>}<EOL><EOL>\" Count is 4 \r\nCount value 5\r\nFallback triggered due to exception: 500 Server Error on GET request for \"http:\/\/localhost:8085\/empmgmt\/test\/employees\/ise\": \"{<EOL><EOL> \"message\": \"500 Internal Server Error\"<EOL><EOL>}<EOL><EOL>\" Count is 5 \r\nCount value 6\r\nFallback triggered due to exception: 500 Server Error on GET request for \"http:\/\/localhost:8085\/empmgmt\/test\/employees\/ise\": \"{<EOL><EOL> \"message\": \"500 Internal Server Error\"<EOL><EOL>}<EOL><EOL>\" Count is 6 \r\nCount value 7\r\nFallback triggered due to exception: 500 Server Error on GET request for \"http:\/\/localhost:8085\/empmgmt\/test\/employees\/ise\": \"{<EOL><EOL> \"message\": \"500 Internal Server Error\"<EOL><EOL>}<EOL><EOL>\" Count is 7 \r\nCount value 8\r\n\u26a0\ufe0f CircuitBreaker [EmployeeService] moved to OPEN state at 2026-08-16T14:16:53.120914500+05:30[Asia\/Calcutta]\r\nFallback triggered due to exception: 500 Server Error on GET request for \"http:\/\/localhost:8085\/empmgmt\/test\/employees\/ise\": \"{<EOL><EOL> \"message\": \"500 Internal Server Error\"<EOL><EOL>}<EOL><EOL>\" Count is 8 \r\nFallback triggered due to exception: CircuitBreaker 'EmployeeService' is OPEN and does not permit further calls Count is 9 \r\nFallback triggered due to exception: CircuitBreaker 'EmployeeService' is OPEN and does not permit further calls Count is 10 \r\nFallback triggered due to exception: CircuitBreaker 'EmployeeService' is OPEN and does not permit further calls Count is 11 \r\nFallback triggered due to exception: CircuitBreaker 'EmployeeService' is OPEN and does not permit further calls Count is 12 \r\nCircuitBreaker [EmployeeService] transitioned: State transition from OPEN to HALF_OPEN\r\nCount value 13\r\nDownstream call took: 2009 ms\r\nCount value 14\r\nDownstream call took: 2006 ms\r\nCount value 15\r\nDownstream call took: 2008 ms\r\nCircuitBreaker [EmployeeService] transitioned: State transition from HALF_OPEN to CLOSED\r\nCount value 16\r\nDownstream call took: 2012 ms\r\nCount value 17\r\nDownstream call took: 2008 ms\r\nCount value 18\r\nDownstream call took: 2016 ms\r\nCount value 19\r\nDownstream call took: 2013 ms\r\nCount value 20\r\nDownstream call took: 2013 ms\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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 \u2014 Closed, Open, and Half\u2011Open \u2014 to balance resilience with recovery. Closed State &#8211; Requests flow&hellip; <a href=\"https:\/\/codethataint.com\/blog\/microservices-patterns-resilence-and-fault-tolerance-circuit-breaker\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[378,379],"tags":[],"class_list":["post-5800","post","type-post","status-publish","format-standard","hentry","category-microservices-patterns","category-resilence-and-fault-tolerance"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5800","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=5800"}],"version-history":[{"count":4,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5800\/revisions"}],"predecessor-version":[{"id":5804,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/5800\/revisions\/5804"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=5800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=5800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=5800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}