{"success":true,"name":"add-a-circuit-breaker-stop-hammering-a-service-that-is-alrea","description":"Your backend depends on an external service that sometimes goes down","category":"ai-brimind","path":"ai-brimind/add-a-circuit-breaker-stop-hammering-a-service-that-is-alrea/SKILL.md","file":"SKILL.md","content":"---\nname: add-a-circuit-breaker-stop-hammering-a-service-that-is-alrea\ndescription: \"Your backend depends on an external service that sometimes goes down\"\n---\n\n# Add a Circuit Breaker: Stop Hammering a Service That Is Already Down\n\n## When to use\nA backend calls an external API or service on the request path, and an outage there currently means every request still tries, waits, and fails.\n\n## Example request\nPayment provider goes down → every user request still waits the full timeout before failing; the app is slow everywhere because one dependency is dead. — Retries fire on every failing call during the outage → your traffic triples against a struggling service; retry without a breaker makes their outage worse and yours longer. — Breaker opens after repeated failures → calls fail instantly with a clear fallback while the service is known-dead; fast failure protects your own threads and users. — After a cooldown, one trial call tests recovery → success closes the breaker gradually; that open/half-open/closed cycle is the named circuit breaker pattern.\n\n## Instructions\nAct as an electrician who installs a fuse: when the line is faulty, the fuse cuts instantly instead of letting every appliance burn waiting. When your backend depends on an external call: 1) Map the blast radius of that dependency failing — which endpoints wait, how long, and what resource (connections, workers) they hold hostage during the wait; timeouts alone still make every request pay the timeout. 2) Add a circuit breaker around the call using an existing library from your ecosystem — this is a named, solved pattern; do not hand-roll the state machine. 3) Configure the three states deliberately: closed (normal, counting failures), open (failure threshold hit → fail instantly for a cooldown period without calling), half-open (after cooldown, let a trial call through; success closes, failure re-opens). Choose the failure threshold and cooldown from the dependency's real behavior, not defaults you never read. 4) Design what an instant failure means for the user BEFORE the outage: cached data, a degraded feature, or an honest 'temporarily unavailable' — the breaker only decides WHEN to fail fast, you must decide WHAT that looks like. 5) Make breaker state visible in logs/metrics so an open breaker is a loud signal, not a silent mystery of missing traffic. If you don't know the dependency's failure modes, check its status history and your own error logs first. Only ship once you've simulated the dependency being down and confirmed requests fail fast with the planned fallback, and explain how the breaker protects your service and theirs — not just retries the pain faster.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #971\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}