Advanced
Circuit Breakers

Circuit Breakers

Prevent cascading failures with built-in resilience patterns.

Boundary implements the circuit breaker pattern to prevent cascading failures when a provider becomes unhealthy.

How It Works

  • Closed (Normal): All requests pass through
  • Open (Failure): Requests fail immediately without hitting the API
  • Half-Open (Testing): Limited requests to test recovery

Configuration

const boundary = new Boundary({
  github: {
    auth: { token: "..." },
    circuitBreaker: {
      threshold: 5,        // Open after 5 failures
      timeout: 60000,      // Try recovery after 60s
      resetTimeout: 30000  // Reset to closed after 30s success
    }
  }
});

Monitoring

You can check the status of a circuit breaker at any time:

const status = boundary.getCircuitStatus("github");
console.log(status); // "closed" | "open" | "half-open"
Production Tip
It is recommended to log circuit breaker stage changes to your specialized monitoring infrastructure (Datadog, Sentry, etc.) to be alerted when a provider is down.