Guide
Kill switches: turn features off in seconds
When a feature or a dependency starts hurting production, the fastest fix is turning it off. Here is how to build kill switches that work at 3 a.m., including when part of your infrastructure is already down.
A kill switch is a long-lived feature flag that turns a feature or a dependency off at runtime, without a deploy. During an incident, an engineer flips it to stop the damage in seconds, then fixes the cause without time pressure.
Why a kill switch beats a rollback
A rollback redeploys the previous version: build, deploy, warm-up, often 10 to 30 minutes, and it also removes every other change in the release. A kill switch changes one behaviour, reaches every instance within seconds, and is just as easy to undo. It also works for problems a rollback cannot fix, such as a third-party API that started failing on its own.
When you need one
- Third-party dependencies: a payment provider, a recommendations API, a search cluster, an LLM call. When it slows down, your requests slow down with it.
- Expensive work: a heavy query, a report export, image processing. Under load, shedding it keeps the core product up.
- New code paths in risky areas such as checkout, sign-in or billing, for the first weeks after launch.
- Background jobs and integrations that can flood a downstream system: email sends, webhooks, syncs.
- Non-essential UI: a chat widget, a banner, personalised sections that call extra services.
How to implement a kill switch
A kill switch is a boolean flag that defaults to on: the code default is the feature running, and the switch turns it off.
// true = the recommendations service is called. Flip to false to shed it.
const recommendationsOn = await flags.getBooleanValue('recommendations-enabled', true, context);
const recommendations = recommendationsOn
? await recommendationsApi.forUser(user.id, { timeout: 800 })
: []; // the degraded but working path
Four rules make the difference between a switch that works and one that doesn't:
- The off path must be boring. Return an empty list, a cached value or a static message. If turning the feature off calls another fragile service, the switch moves the problem instead of stopping it.
- Default to the feature running. If the flag system can't answer, the code default is used. For a kill switch, that should be normal operation, not an accidental outage.
- Evaluate locally. Incidents often involve network trouble. A server SDK that holds the rules in memory keeps answering, and keeps the last known value, even if it can't reach the flag service. A switch that needs a network call per check can fail exactly when you need it.
- Check it at the right place. Put the check where the cost is: before the outbound call or the expensive query, not in the UI that displays the result.
How granular should a kill switch be?
One switch per dependency or per feature is the usual sweet spot. A single "maintenance mode" switch is too coarse: it turns off everything to stop one thing. One switch per endpoint is too fine: nobody remembers which to flip. Targeting rules let one switch be precise when it needs to be, for example off only for one region, one customer or one platform while you investigate.
Test it before the incident
- Test both paths in CI: run the code with the switch on and off.
- Flip it in staging regularly, and in production during a quiet period if the off path is customer-safe. A switch that has never been flipped is a hypothesis.
- Measure how long it takes from the click to every instance changing behaviour. With streaming updates it should be about a second; with polling it is the polling interval.
- Put it in the runbook: which alert means "flip this switch", who may flip it, and how to tell it worked.
Who can flip a kill switch, and how fast
Production changes deserve review, but an incident cannot wait for one. A good setup separates the two: on-call engineers can flip a switch directly, with a reason that goes into the audit log, while automated changes still wait for a person.
In Railflag, mark the flag as an ops flag so nobody cleans it up as a finished release. A person with edit rights changes Production immediately, with the reason recorded. Changes requested by tokens or AI agents, for example through the MCP server's toggle_flag tool, wait for a person to approve them.
Kill switch vs circuit breaker
| Kill switch | Circuit breaker | |
|---|---|---|
| Triggered by | A person | Error rate or latency thresholds |
| Scope | Every instance, all at once | Usually per instance |
| Recovers | When a person turns it back on | Automatically, after probing |
| Best for | Decisions: "stop doing this until we say so" | Fast automatic protection from flaky dependencies |
They complement each other. The breaker reacts in milliseconds; the switch makes the decision stick while you investigate.
Common mistakes
- Inverted names.
disable-recommendations = truemeans off, and someone will get it backwards under stress. Name switches so that true means running. - Cleaning them up. Kill switches look like stale flags because they never change. Mark them as long-lived so cleanup tools leave them alone.
- Remote evaluation on the hot path. If every check calls the flag service, the flag service becomes a dependency of every request.
- No owner. A switch that nobody remembers is a switch nobody flips in time.
Frequently asked questions
- What is a kill switch in software?
- A kill switch is a long-lived feature flag that turns a feature or a dependency off at runtime, without a deploy. Engineers flip it during an incident to stop the damage while they find the cause.
- Is a kill switch the same as a circuit breaker?
- No. A circuit breaker trips automatically when error rates cross a threshold and closes again by itself. A kill switch is a deliberate decision by a person. Many systems use both: the breaker for fast automatic protection, the kill switch for a decision that should stick.
- Should a kill switch be on or off by default?
- The feature should be on by default and the switch should turn it off. Name the flag so that true means the feature runs, and make the code default true, so the feature keeps working if the flag system cannot answer.
- How long should a kill switch live?
- As long as the risky code path or dependency exists. Unlike release flags, kill switches are permanent, so give each one an owner, a description and a runbook entry, and test it regularly.
Kill switches that work during an outage
Railflag's server SDKs evaluate in your process and keep the last rules if they lose contact, and a flipped switch reaches every instance within a second.
Start for free