Skip to content
Back to skills

Circuit Breaker

ASecurity

Implement circuit breaker patterns to prevent cascading failures in distributed systems and enable graceful degradation.

  • 3 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 6, 2026
ai-agentspythongotesting

Works with

  • cursor
  • cli

Security analysis

A100/100

Scanned September 6, 2026

npx -y skills add AtulPurohit/Antigravity-Awesome-Skills --skill circuit-breaker --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Circuit Breaker?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Circuit Breaker
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/atulpurohit-circuit-breaker/badge)](https://www.skillsdirectory.com/skills/atulpurohit-circuit-breaker)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: circuit-breaker
description: "Implement circuit breaker patterns to prevent cascading failures in distributed systems and enable graceful degradation."
category: architecture
tags: [circuit-breaker, resilience, fault-tolerance, microservices]
complexity: advanced
risk: low
compatibility: [claude-code, antigravity, gemini-cli, cursor, copilot, codex-cli, autohand, kiro]
source: antigravity-official
version: "1.0.0"
date_added: "2026-07-10"
last_updated: "2026-07-10"
---

# Circuit Breaker Implementer

## Purpose
Prevent cascading failures in microservices by detecting failing dependencies and failing fast with fallback behavior.

## Circuit Breaker States
```
CLOSED (normal): Requests flow through, failures tracked
   ↓ threshold exceeded
OPEN (failed): Requests rejected immediately, no calls to dependency
   ↓ after timeout
HALF-OPEN (testing): Limited requests allowed through to test recovery
   ↓ success
CLOSED (recovered)
   ↓ failure
OPEN again
```

## Implementation (Python)
```python
class CircuitBreaker:
    def __init__(self, failure_threshold=5, timeout=60, success_threshold=2):
        self.failure_count = 0
        self.success_count = 0
        self.state = 'CLOSED'
        self.failure_threshold = failure_threshold
        self.timeout = timeout
        self.success_threshold = success_threshold
        self.last_failure_time = None
    
    def call(self, fn, *args, **kwargs):
        if self.state == 'OPEN':
            if time.time() - self.last_failure_time > self.timeout:
                self.state = 'HALF-OPEN'
            else:
                raise CircuitOpenError("Circuit is OPEN")
        
        try:
            result = fn(*args, **kwargs)
            self._on_success()
            return result
        except Exception as e:
            self._on_failure()
            raise
    
    def _on_success(self):
        if self.state == 'HALF-OPEN':
            self.success_count += 1
            if self.success_count >= self.success_threshold:
                self.state = 'CLOSED'
                self.failure_count = 0
    
    def _on_failure(self):
        self.failure_count += 1
        self.last_failure_time = time.time()
        if self.failure_count >= self.failure_threshold:
            self.state = 'OPEN'
```

## Fallback Strategies
- **Default values**: Return cached/default data
- **Graceful degradation**: Serve reduced functionality
- **Queue for later**: Store request for retry when service recovers

## Outputs
1. Circuit breaker implementation
2. Fallback handler configuration
3. State monitoring dashboard
4. Alert rules for circuit opening
5. Recovery testing procedures

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…