Problem Statement
Describe the Circuit Breaker pattern and where you would place it in a microservices call path.
Explanation
Circuit Breaker tracks recent failures when calling a dependency. After a threshold, it opens and fails fast. After a cool-off, it half-opens and probes. If probes succeed, it closes again. The goal is to avoid cascading failures and protect shared resources.
Place it in the client library or gateway where calls originate. Combine with timeouts, bulkheads, and fallbacks. Expose metrics so SREs can tune thresholds per dependency and traffic pattern.
Code Solution
SolutionRead Only
if (breaker.open) throw FastFail;
try{ resp=call(); breaker.recordSuccess(); } catch(e){ breaker.recordFailure(); }