Circuit breaker pattern

From aj-geddes/useful-ai-prompts · View interactive version

Circuit breaker pattern is an AI agent skill from the GitHub repository aj-geddes/useful-ai-prompts. Implement circuit breaker patterns for fault tolerance, automatic failure detection, and fallback mechanisms. Use when calling external services, handling cascading failures, or implementing resilience patterns.

How to use this skill

Skill file

Circuit Breaker Pattern

Table of Contents

Overview

Implement circuit breaker patterns to prevent cascading failures and provide graceful degradation when dependencies fail.

When to Use

Quick Start

Minimal working example:

enum CircuitState {
  CLOSED = "CLOSED",
  OPEN = "OPEN",
  HALF_OPEN = "HALF_OPEN",
}

interface CircuitBreakerConfig {
  failureThreshold: number;
  successThreshold: number;
  timeout: number;
  resetTimeout: number;
}

interface CircuitBreakerStats {
  failures: number;
  successes: number;
  consecutiveFailures: number;
  consecutiveSuccesses: number;
  lastFailureTime?: number;
}

class CircuitBreaker {
  private state: CircuitState = CircuitState.CLOSED;
  private stats: CircuitBreakerStats = {
    failures: 0,
// ... (see reference guides for full implementation)

Reference Guides

Detailed implementations in the references/ directory:

| Guide | Contents |

|---|---|

| TypeScript Circuit Breaker | TypeScript Circuit Breaker |

| Circuit Breaker with Monitoring | Circuit Breaker with Monitoring |

| Opossum-Style Circuit Breaker (Node.js) | Opossum-Style Circuit Breaker (Node.js) |

| Python Circuit Breaker | Python Circuit Breaker |

| Resilience4j-Style (Java) | Resilience4j-Style (Java) |

Best Practices

✅ DO

❌ DON'T

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.