circuit-breaker-pattern

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.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "circuit-breaker-pattern" with this command: npx skills add aj-geddes/useful-ai-prompts/aj-geddes-useful-ai-prompts-circuit-breaker-pattern

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

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

nodejs-express-server

No summary provided by upstream source.

Repository SourceNeeds Review
General

markdown-documentation

No summary provided by upstream source.

Repository SourceNeeds Review
General

rest-api-design

No summary provided by upstream source.

Repository SourceNeeds Review
General

architecture-diagrams

No summary provided by upstream source.

Repository SourceNeeds Review