A toggle is a switch that lets you turn things on or off. People use toggles to control things like TVs, lights, and heat. A toggle can also be used to turn something on or off in a computer program.
A feature flag is a way to enable a new behavior for a small group of users while keeping existing functionality available for all others. For example, a company might want to test out a new payment process but it needs to keep the existing one running for existing customers. Using a feature flag, the company can change which route a user gets taken when they click a button. The company can then collect data from a subset of users and see which path yields the best results.
Traditionally, teams managed toggle configuration via static files. But as toggle configuration grew in size and scope this became unwieldy, especially when multiple teams were sharing the same codebase. A more modern approach is to move the toggle configuration into some type of centralized store, often an existing application DB. This usually comes with some form of admin UI that system operators, testers and product managers can use to view and modify the state of a toggle.
It’s important that the design of a toggle is accessible for disabled users. A common mistake is to simply make the toggle switch appear differently, using green for “on” and red for “off”. But this is problematic for people with color blindness or other impairments. In addition, it’s hard to convey the meaning of a toggle using visual clues alone.
Because they enforce a mutually exclusive state, toggles tend to be more confusing than buttons that let you select multiple values in a list. Because of this, designers try to mitigate confusion by making them as clear as possible. They generally do this by putting them in context, clearly identifying the setting, view or content that they affect and updating their appearance (typically, by changing the background) based on their current state.
Some toggles will live for just a few days or weeks while others will be semi-permanent. Savvy teams take this into account and attempt to minimize the number of toggles they have in their codebase. To do this they will often add a task to their backlogs when a Release Toggle is first introduced to remove the feature flag once it’s no longer needed. They may even go as far as adding an expiration date to a toggle and creating a set of tests that fail if a toggle is still around after its time has passed.
Regardless of the approach that a team takes to managing their toggle configuration it is important to test all of the scenarios that they might encounter. This means testing the toggle configuration that they expect to be live in production with all of the toggles flipped On and testing the fallback configuration with all of the toggles flipped Off.