Why ship code that is switched off?
Hiding a half-finished feature behind a switch lets a team keep merging and releasing, and gives them an emergency off button.
โถ Start the storyProgrammers ship code that is switched off because it lets them release unfinished work safely. A feature toggle, also called a , is a condition in the code that turns a feature on or off while the program is running. The new code travels to production with everything else, but it stays hidden until someone flips the switch. Release becomes a decision, separate from the moment the code arrives.
This solves a problem for teams that merge often. Instead of keeping a feature on a long-lived branch, developers check unfinished work into the shared code. The toggle keeps it out of sight, so the shared code can still be deployed to production at any time. The incomplete and untested code is shipped as , which may never be turned on at all.
Long-lived branch
- Work stays apart from the shared code
- Merging at the last moment risks conflicts
Feature toggle
- Code lives in shared code
- Hidden until switched on
- Can be switched off at once
Toggles also work as dials. A team can switch a new version on for internal users only, test it in production, and then widen the group. Flags can target people by location or user attributes. And a lets operators turn a feature off in a hurry, for instance to deal with an incident or reduce load.
The price is clutter. Toggles add extra conditional logic and a significant testing burden. Toggles that stay after a feature is permanently on become , known as toggle debt. Even Martin Fowler says a release toggle should be your last choice. And Knight Capital's trading disaster, the subject of a later lesson, is cited as a warning about unmanaged flags.
Quiz me
0/3
Recap
Ship the code dark, switch it on for a few, and remove the switch when you are done.
๐ก A trick to remember it ยท Every switch needs a sunset: install it, use it, remove it, or it turns into clutter.
Surprising fact ยท A single article on toggles cites Knight Capital's $460 million mistake as a warning about unmanaged flags.
Sources (2)
No source, no claim. Every fact in this lesson (15 claims) cites at least one of these.