Kill Switches
Use feature flags as emergency toggles to instantly disable features in production
A kill switch is a boolean feature flag designed to instantly disable a feature when something goes wrong — without redeploying your application.
When to use kill switches
- Third-party service outage — disable features that depend on an external API
- Bug discovered in production — turn off the broken feature immediately
- Security incident — disable a compromised feature while investigating
- Performance degradation — reduce load by disabling expensive features
- Capacity limits — disable non-critical features during traffic spikes
Setting up a kill switch
Step 1: Create the flag
Create a boolean flag with a descriptive key:
payments-enabledsearch-enablednotifications-enabledfile-uploads-enabled
Name kill switches after the feature they protect, not after the failure scenario. This makes them easy to find in the dashboard.
Step 2: Wrap the feature
const isPaymentsEnabled = client.isEnabled('payments-enabled', true)
if (!isPaymentsEnabled) {
return showMaintenanceMessage('Payments are temporarily unavailable.')
}
// Normal payments flow
processPayment(order)
import { useFlag } from '@flagpool/react'
function PaymentForm() {
const isPaymentsEnabled = useFlag('payments-enabled', true)
if (!isPaymentsEnabled) {
return <Alert>Payments are temporarily unavailable. Please try again later.</Alert>
}
return <CheckoutForm />
}
if not client.is_enabled("payments-enabled"):
return maintenance_response("Payments are temporarily unavailable.")
# Normal payments flow
process_payment(order)
if !client.IsEnabled("payments-enabled") {
return maintenanceResponse("Payments are temporarily unavailable.")
}
// Normal payments flow
processPayment(order)
Step 3: Enable by default
In the dashboard, set the flag to enabled for all environments. The flag stays on during normal operation and is only turned off in an emergency.
Using the kill switch
When an incident occurs:
- Go to the Flagpool dashboard
- Find the kill switch flag (e.g.,
payments-enabled) - Toggle it off for the affected environment
- The change propagates via CDN in under 50ms
SDKs pick up the change on their next poll (30 seconds by default). If you need faster propagation, enable streaming or use a shorter polling interval.
Default values matter
Always set the default value to the safe state. For kill switches, this means defaulting to true (enabled):
// Default to true — if the flag can't be evaluated, the feature stays on
const isEnabled = client.isEnabled('payments-enabled', true)
This ensures that if the SDK hasn't initialized yet, or if there's a network issue fetching flags, the feature remains available. You only want the feature to go down when you explicitly flip the switch.
Kill switch patterns
Single service dependency
One flag per external dependency:
const isStripeEnabled = client.isEnabled('stripe-payments-enabled', true)
const isSendgridEnabled = client.isEnabled('email-notifications-enabled', true)
const isAlgoliaEnabled = client.isEnabled('search-enabled', true)
Tiered degradation
Use multiple flags for graceful degradation:
// Full feature
if (client.isEnabled('ai-recommendations-enabled', true)) {
return getAIRecommendations(user)
}
// Fallback: simpler algorithm
if (client.isEnabled('basic-recommendations-enabled', true)) {
return getBasicRecommendations(user)
}
// Last resort: static content
return getPopularItems()
Load shedding
Disable non-critical features during traffic spikes:
const isLowPriority = !client.isEnabled('non-critical-features-enabled', true)
if (isLowPriority) {
// Skip analytics tracking, recommendations, etc.
return minimalResponse(data)
}
return fullResponse(data)
Best practices
- Name clearly — use
*-enabledsuffix so it's obvious what "on" and "off" mean - Default to enabled — the safe state during SDK initialization should keep features working
- Document dependencies — maintain a list of which kill switches protect which external services
- Test your kill switches — periodically verify that toggling the flag actually disables the feature gracefully
- Set up alerts — monitor the flag state and alert your team when a kill switch is activated
Next steps
- Feature Flags — core concepts
- Rollouts — gradual rollback via percentage
- Environments — manage kill switches per environment