What is a Toggle?
A toggle is a switch that has two positions, on or off. A toggle is often found in a physical button on a computer or device that controls the state of a feature such as WiFi on/off. In software, toggles are commonly used to adjust settings. They are preferred to radio buttons for mobile devices because they take up less space and deliver immediate results. The word toggle was originally a noun meaning “pin passed transversely through the eye or loop of a rope or chain so as to bind it temporarily.” Toggle is also used as an adjective meaning “switch back and forth” like switching between video chat and texting with two different friends at once.
While toggles are easy to use they can be confusing for users if not implemented consistently. Toggle switches should be clearly labeled and use standard visual design. In addition, they should be presented in a manner that reflects the meaning of the control (ON or OFF). When paired with a checkbox toggles should be placed on the right side of the screen so that the user can easily see the status.
Toggles are also useful for managing Feature Flags. In this case the toggles may be flipped to enable or disable new features in a production release. Savvy teams view their Feature Toggle inventory as a carrying cost and seek to keep that inventory low by being proactive about removing toggles when they are no longer needed. Some teams even go so far as to put “expiration dates” on their toggles and will re-deploy code when those expirations pass.
For more complex usages of Toggles such as A/B testing it is possible to use a special configuration of the toggle system to create an experiment. Each user is assigned to a cohort and at runtime the Toggle Router will consistently send them down one of the codepaths, tracking their behavior over time. This allows you to make data-driven improvements to things such as the purchase flow on an ecommerce site or the Call To Action wording on a button.
Toggles are a very powerful tool in the hands of a software team, but they can be dangerous when used recklessly. To avoid a potential disaster it is best to use the most lightweight approach to toggle configuration that will still allow you to dynamically re-configure individual service instances. For example commenting on a line of code or using a preprocessor’s #ifdef can be more sophisticated than a plain static file approach but they still don’t provide the benefit of dynamic in-memory re-configuration.