A toggle is a switch that allows you to turn something on or off. It can be used in software, hardware or a physical device. For example, the cap lock and num lock keys on a keyboard are toggles that allow you to turn a particular function on or off. A toggle can also be a piece of software that you use to control certain aspects of your computer or web browser. For example, a toggle can be used to control how much storage is available on your hard drive or to manage privacy settings.
A feature toggle is a way to turn on and off features that are in development. It’s often used to support agile approaches to software development and to reduce the need for code branches that would otherwise block feature releases. Typically, a team will create a toggle in the codebase to hide new features until they’re ready for release or testing. Once a team is confident that a new feature is complete it will remove the toggle and allow the feature to be pushed to production.
There are four general categories of toggles: experimentation, permissions, monetization and privacy. Each category of toggles has its own best practices for managing and deploying them.
When a toggle is in an experimentation phase it should be visible to a small subset of your user base. This enables you to get feedback on the functionality before it’s exposed to your entire user base. This is often referred to as an “alpha” or a “beta” version of a feature.
This type of toggle is short-lived compared to other categories of Feature Toggles. It is a great way to test out a new feature before releasing it for everyone. For example, an ecommerce company might want to see if their users prefer one suggestion algorithm over another before implementing it for all users. This could be easily tested by adding an experiment toggle to the configurator that splits users into two cohorts based on their modulo when they load the configurator. Once the ecommerce company has conclusive data that shows which algorithm performs better they will remove the experiment toggle and implement it for all users.
While a toggle is active it should not consume too many resources. If a toggle is dynamic and requires a database call every time it changes you may be creating thousands or even millions of queries for a rarely changing value. This can cause performance issues in production and should be avoided when possible.
A good practice for naming toggles is to give them names that clearly describe the setting, view or content they control. This will help people on other teams understand what the toggle does when it appears in error messages or other contexts. This is especially important when teams are using multiple tools to manage their feature toggles. It’s easy to mix up the name of a toggle if it has more than one or two siblings.