CodingSaves ~1 hour
Implement a circuit breaker pattern
Protect your application from cascading failures caused by degraded external dependencies.
The prompt
You are a resilience engineering expert. Implement the circuit breaker pattern in [LANGUAGE] for protecting calls to external services. The implementation must include: three states (Closed, Open, Half-Open) with clear transition logic, configurable failure threshold (count and percentage within a time window), configurable reset timeout (how long to stay Open before trying Half-Open), thread-safe state management, event callbacks for state transitions (for monitoring), integration example wrapping an HTTP client call, fallback function support (what to return when the circuit is Open), and metrics emission (success count, failure count, state changes). Include a state machine diagram in comments. Language: [LANGUAGE] Use case: [DESCRIBE THE EXTERNAL SERVICE] Failure threshold: [e.g. 5 failures in 30 seconds]
Replace the [BRACKETED] fields with your details, then paste into ChatGPT, Claude or Gemini.
Want AI to fill this in for you?
Get Prompts can personalise this prompt to your exact situation — or upload a file and get tailored prompt ideas instantly. 3 free edits, no sign-up.
Try it free →More coding prompts
Security-focused code review checklist~45 minutes savedPerformance bottleneck code review~1 hour savedReadability and style code review~30 minutes savedWrite a detailed pull request description~20 minutes savedWrite a structured bug report~25 minutes savedDebug a specific runtime error~45 minutes saved