When to Use a Toggle

A toggle is a switch that can be set in one of two states. Toggle switches are the preferred control for adjusting settings on mobile devices because they take up less space than a checkbox and come with a pre-selected state (ON or OFF).

The term “toggle” can also refer to the switching between different views of an application or website. For example, many social media apps allow you to toggle between a stream view and a map view. Often, these are used to display different features of the app that aren’t available in the standard view.

Toggles are a useful tool in the feature flagging arsenal because they can be used to enable or disable new features in a production environment without deploying a full changeset. This allows teams to experiment with new feature ideas and get fast feedback from users without interrupting the normal flow of CI/CD processes.

When to Use a Toggle

A good rule of thumb is to only use toggles when it makes sense to have an On/Off option available. This could be because the behavior is critical to a core part of the product or because it provides a significant business benefit.

If you’re using toggles to enable new features in a production environment it’s important that your team test each toggle configuration in its expected production state. In addition, it’s usually a good idea to test the fall-back configuration of each toggle flipped Off. This can help avoid surprise regressions in the event that the toggle is rolled back to a previous state in the future.

One of the challenges with this approach is that it can be difficult to manage a large number of toggles using static files. It can also be hard to re-test configuration changes consistently and efficiently. This is why savvy teams tend to move their toggle configuration into some type of centralized store, often an existing application DB.

Once this is done it’s generally easier to update toggle configuration in a centralized way and this can be easier for both the automated tests and manual exploratory testing and debugging. It’s also easier to make sure that the change is applied across a fleet of servers in the same manner. Using this approach also enables better monitoring of the toggle configuration in a production environment.