mcpField
C
circuit-breaker-pattern

circuit-breaker-pattern

github.com/aj-geddesDevelopment373476 installsUpdated 34w ago
Repository

About circuit-breaker-pattern

A reference skill for implementing circuit breakers in services that depend on external systems. It covers failure handling, fallbacks, monitoring, and language-specific examples.

Key features

  1. 01Circuit states and thresholds
  2. 02Fallback and timeout guidance
  3. 03Monitoring state changes
  4. 04TypeScript, Python, and Java guides

Use cases

  1. 01Protecting external API calls
  2. 02Handling microservice or database failures
  3. 03Limiting cascading failures

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill circuit-breaker-pattern

After installing, type/circuit-breaker-patternin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
circuit-breaker-with-monitoring.md
opossum-style-circuit-breaker-nodejs.md
python-circuit-breaker.md
resilience4j-style-java.md
typescript-circuit-breaker.md
scripts/
validate-api.sh
templates/
api-scaffold.yaml

Details

From the project README

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

  • External API calls
  • Microservices communication
  • Database connections
  • Third-party service integrations
  • Preventing cascading failures
  • Implementing fallback mechanisms
  • Rate limiting protection
  • Timeout handling

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:

GuideContents
TypeScript Circuit BreakerTypeScript Circuit Breaker
Circuit Breaker with MonitoringCircuit Breaker with Monitoring
Opossum-Style Circuit Breaker (Node.js)Opossum-Style Circuit Breaker (Node.js)
Python Circuit BreakerPython Circuit Breaker
Resilience4j-Style (Java)Resilience4j-Style (Java)

Best Practices

✅ DO
  • Use appropriate thresholds for your use case
  • Implement fallback mechanisms
  • Monitor circuit breaker states
  • Set reasonable timeouts
  • Use exponential backoff
  • Log state transitions
  • Alert on frequent trips
  • Test circuit breaker behavior
  • Use per-dependency breakers
  • Implement health checks
❌ DON'T
  • Use same breaker for all dependencies
  • Set unrealistic thresholds
  • Skip fallback implementation
  • Ignore open circuit breakers
  • Use overly aggressive reset timeouts
  • Forget to monitor

Comments

Markdown supported