Use Claude to Implement the Circuit Breaker Pattern
The circuit breaker pattern stops a failing service from taking down your whole app — and Claude can scaffold it from a plain-English description of your requirements.
Implement a circuit breaker for our PaymentServiceClient. After 5 consecutive failures
open the circuit and return a cached fallback response for 30 seconds, then move to
half-open to test with a single request before fully closing again.
Claude will generate the three-state machine (closed → open → half-open), the failure counter, and the reset timeout — wired into your existing HTTP client. It also knows idiomatic libraries for your stack: resilience4j for Java/Kotlin, Polly for .NET, or a clean custom class for PHP or Python.
Once the core is in place, ask Claude to test it:
Write a test suite that simulates a flapping service. Verify the circuit opens after
5 failures, returns the fallback during the open state, and correctly closes again
after a successful probe request.
You can also ask for an observable version that emits metrics when the circuit changes state — useful for dashboards and alerting.
Circuit breakers are one of those patterns everyone knows they should add but rarely does because of the boilerplate. Claude removes that excuse.
Resilient systems aren't built by hoping dependencies stay up — they're built by assuming they won't.
Log in to leave a comment.
The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.
The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.
Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.