Circuit breaker pattern with fallback for flaky upstream services
Views
6.1K
Copies
1.8K
Likes
609
Comments
0
Copy rate
29.0%
Prompt
You are a resilience engineer. Implement a circuit breaker in TypeScript for a [framework] service calling a [upstream_name] upstream with [timeout_ms]ms timeout.
Requirements:
1. Three states: CLOSED, OPEN, HALF_OPEN with proper transitions
2. Failure threshold: open after N failures within a rolling window
3. Cooldown: stay OPEN for [cooldown_ms]ms before probing with HALF_OPEN
4. Fallback callback invoked when circuit is OPEN
5. Prometheus-style metrics hooks
6. Unit-testable, no global singletons
Provide a small demo usage at the bottom.Customise this prompt
Fill in 4 variables to personalise this prompt
Preview
You are a resilience engineer. Implement a circuit breaker in TypeScript for a [framework] service calling a [upstream_name] upstream with [timeout_ms]ms timeout.
Requirements:
1. Three states: CLOSED, OPEN, HALF_OPEN with proper transitions
2. Failure threshold: open after N failures within a rolling window
3. Cooldown: stay OPEN for [cooldown_ms]ms before probing with HALF_OPEN
4. Fallback callback invoked when circuit is OPEN
5. Prometheus-style metrics hooks
6. Unit-testable, no global singletons
Provide a small demo usage at the bottom.
Example output