Circuit Breaker Feature Flag

Use feature flags as circuit breakers to protect your application from cascading failures by disabling non-critical functionality during outages.

Safety Patterns

Detailed Explanation

Circuit Breaker Feature Flags

A circuit breaker flag automatically or manually disables a non-critical service dependency when it becomes unreliable. This prevents cascading failures where one failing service brings down the entire application.

Configuration Example

{
  "recommendation-engine-enabled": {
    "name": "Recommendation Engine Circuit Breaker",
    "description": "Disable to stop calls to recommendation service during outages",
    "type": "boolean",
    "enabled": true,
    "defaultValue": true,
    "targeting": []
  },
  "social-proof-enabled": {
    "name": "Social Proof Widget Circuit Breaker",
    "description": "Disable to hide 'X people viewing this' widget",
    "type": "boolean",
    "enabled": true,
    "defaultValue": true,
    "targeting": []
  }
}

Circuit Breaker States

CLOSED (normal) → Service is healthy, flag is ON
    |
    v (failures exceed threshold)
OPEN (tripped) → Service is failing, flag is OFF
    |
    v (cooldown period passes)
HALF-OPEN (testing) → Allow limited traffic to test recovery
    |
    v (success)
CLOSED (normal) → Restore full traffic

Graceful Degradation Strategies

Service When Disabled Fallback
Recommendations Hide "Recommended for you" section Show popular items
Search Disable instant search Fall back to basic SQL search
Social proof Hide "X people viewing" Show nothing
Email notifications Queue emails Send batch later
Analytics tracking Stop tracking calls Buffer events locally

Manual vs Automatic

Manual circuit breakers (using feature flags):

  • Toggled by on-call engineer during incidents
  • Simple to implement
  • Requires human judgment and response time

Automatic circuit breakers (using code + flags):

  • Application code monitors failure rates
  • Automatically opens the circuit when threshold is exceeded
  • Feature flag provides a manual override

Implementation Pattern

async function getRecommendations(userId: string) {
  // Check the circuit breaker flag first
  if (!featureFlags.isEnabled("recommendation-engine-enabled")) {
    return getPopularItems(); // Fallback
  }

  try {
    return await recommendationService.getForUser(userId);
  } catch (error) {
    // Log the failure for monitoring
    metrics.increment("recommendation.failure");
    return getPopularItems(); // Fallback on error too
  }
}

Best Practices

  • Identify all external dependencies and create a circuit breaker for each
  • Test fallback paths regularly (chaos engineering)
  • Set up dashboards showing which circuit breakers are currently open
  • Define clear ownership for each circuit breaker flag

Use Case

An e-commerce site depends on a recommendation engine that occasionally has latency spikes. A circuit breaker flag lets the team instantly disable recommendation API calls during these spikes, showing popular products instead. This prevents the slow recommendation service from increasing page load times for all users.

Try It — Feature Flag Config Generator

Open full tool