Circuit Breaker Pattern

Circuit Breaker Pattern

Teaches an AI agent to implement circuit breakers with fallbacks and failure detection for calls to external services, with TypeScript, Python, Java and Node examples.

Skill files8 files

references/

scripts/

templates/

SKILL.md102 lines
1
---
2
name: circuit-breaker-pattern
3
description: >
4
Implement circuit breaker patterns for fault tolerance, automatic failure
5
detection, and fallback mechanisms. Use when calling external services,
6
handling cascading failures, or implementing resilience patterns.
7
---
8
9
# Circuit Breaker Pattern
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
Implement circuit breaker patterns to prevent cascading failures and provide graceful degradation when dependencies fail.
22
23
## When to Use
24
25
- External API calls
26
- Microservices communication
27
- Database connections
28
- Third-party service integrations
29
- Preventing cascading failures
30
- Implementing fallback mechanisms
31
- Rate limiting protection
32
- Timeout handling
33
34
## Quick Start
35
36
Minimal working example:
37
38
```typescript
39
enum CircuitState {
40
CLOSED = "CLOSED",
41
OPEN = "OPEN",
42
HALF_OPEN = "HALF_OPEN",
43
}
44
45
interface CircuitBreakerConfig {
46
failureThreshold: number;
47
successThreshold: number;
48
timeout: number;
49
resetTimeout: number;
50
}
51
52
interface CircuitBreakerStats {
53
failures: number;
54
successes: number;
55
consecutiveFailures: number;
56
consecutiveSuccesses: number;
57
lastFailureTime?: number;
58
}
59
60
class CircuitBreaker {
61
private state: CircuitState = CircuitState.CLOSED;
62
private stats: CircuitBreakerStats = {
63
failures: 0,
64
// ... (see reference guides for full implementation)
65
```
66
67
## Reference Guides
68
69
Detailed implementations in the `references/` directory:
70
71
| Guide | Contents |
72
|---|---|
73
| [TypeScript Circuit Breaker](references/typescript-circuit-breaker.md) | TypeScript Circuit Breaker |
74
| [Circuit Breaker with Monitoring](references/circuit-breaker-with-monitoring.md) | Circuit Breaker with Monitoring |
75
| [Opossum-Style Circuit Breaker (Node.js)](references/opossum-style-circuit-breaker-nodejs.md) | Opossum-Style Circuit Breaker (Node.js) |
76
| [Python Circuit Breaker](references/python-circuit-breaker.md) | Python Circuit Breaker |
77
| [Resilience4j-Style (Java)](references/resilience4j-style-java.md) | Resilience4j-Style (Java) |
78
79
## Best Practices
80
81
### ✅ DO
82
83
- Use appropriate thresholds for your use case
84
- Implement fallback mechanisms
85
- Monitor circuit breaker states
86
- Set reasonable timeouts
87
- Use exponential backoff
88
- Log state transitions
89
- Alert on frequent trips
90
- Test circuit breaker behavior
91
- Use per-dependency breakers
92
- Implement health checks
93
94
### ❌ DON'T
95
96
- Use same breaker for all dependencies
97
- Set unrealistic thresholds
98
- Skip fallback implementation
99
- Ignore open circuit breakers
100
- Use overly aggressive reset timeouts
101
- Forget to monitor
102

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…