A toggle is a hardware or software switch that can be either ON or OFF. It is often found in options menus where a user can enable or disable various settings for the product. A good example would be the Caps Lock or Num Lock keys on a keyboard. Pressing them once toggles the function on and pressing them again toggles it off. The word toggle is also used to refer to the act of switching between two functions at a high speed, such as when you are video chatting with two friends simultaneously and toggle between their screens.
Feature Toggles are the primary mechanism for managing and controlling the state of your system. They allow you to quickly experiment with different configurations without risking production and to rollout only those configurations that prove successful. For this reason a well-designed and executed toggle system is the foundation for any DevOps platform.
Toggles are best suited for things that have only two outcomes (ON or OFF). This makes them a perfect control for system settings or preferences where you want to provide users with a simple ON/OFF choice. They are also the preferred control for things like Airplane Mode on mobile where screen estate is at a premium.
When you are working with a toggle it is important to ensure that the configuration is properly tested before rolling it out to production. This means testing not only the toggle in its current configuration but also the fallback configuration which will be enabled if the toggle is flipped Off. It is also wise to test with all toggles flipped On so that any potential regressions are quickly identified.
Many teams use a system of backlog items and a process for proactively removing toggles that are no longer needed. Others use “expiration dates” for their toggles which will trigger a failure in a test (or even prevent the application from starting at all) when that toggle reaches its end of life.
Static toggle configurations are fine at a small scale but at some point you will run into issues where you need to modify a toggle at a large or distributed scale. This can be a time-consuming exercise when you need to change the toggle configuration by hand or if you deploy your toggles via a static file and need to re-deploy code into an environment in order to make a modification. To help with these situations consider a solution which provides for dynamic in-memory re-configuration of a toggle.