Intro to Feature Toggles

Intro to Feature Toggles

What is a Feature Toggle?

Feature toggles (sometimes referred to as feature flags) are an engineering practice aiming to control application behavior without the need to deploy a code change. The behaviors that toggles can affect range from hiding under development features, limited feature release (canary) to a subset of users, or used to switch to fallback implementation in the event of a system issue, and more.

These feature toggles are defined outside of the codebase in a shared datastore or service that the application can look up at runtime to determine the status (traditionally on or off, but some features toggle implementations can accept more descriptive values).

Benefits of Feature Toggles

Feature toggles provide many benefits; the main advantage is that they decouple the release of application features and operational changes from the traditional application code deployment pipeline.

Feature toggles enable releasing features before they are tested or even finished, supporting one of the critical principles of continuous delivery. The functionality behind a feature toggle can be enabled in lower environments (Dev, QA, Staging) for testing. Once the testing team has validated the functionality, the operations team can enable the feature toggle in Production.

Another powerful aspect of feature toggles is the ability to control the granularity of releasing a feature or functionality to application end users. This could mean supporting an A/B testing pattern where a feature is only released to a subset of users for early feedback before releasing the feature to everyone. Alternatively, the feature could be controlled by an opt-in user interaction allowing the feature to be dynamically enabled on-demand for each user that requests, with the ability to turn the feature back off again.

These fine-grained controls on how features are rolled out to users mitigate risks of introducing significant new features or overhauls of existing features and provide a crucial feedback loop with your customers and early feature adopters.

Feature toggles ultimately give the engineering and product teams the confidence to embrace rapid changes rather than fearing them as risky endeavors.

Drawbacks of Feature Toggles

While the benefits of feature toggles are vast, as already explored, it is essential to acknowledge some potential drawbacks or negatives in their use and management. Feature toggles introduce additional complexity into an application’s codebase, development lifecycle, and deployment pipeline, requiring discipline and administration overhead to manage successfully.

Efficient feature toggle tooling with diligent toggle upkeep (minimizing the number of active feature toggles in the system) can reduce the impact of these complexities. Development and operations teams need to work together to monitor and manage active toggles, removing toggles from both the codebase and the feature toggle system as they are no longer required.

Feature toggles also provide some challenges related to application testing, expanding the test matrix with the number of feature flag combinations that exist in the system at any time. Feature toggle testing is vital for functionality controlled by a long-lived toggle (see operation toggle type below), ensuring this fallback/legacy functionality has not regressed and is ready to be implemented in an outage.

Types of Feature Toggles

There are four types of feature toggles, which primarily differ in usage and expected lifetime.

Development Toggle

Development toggles ensure incomplete or untested features can be committed to the codebase and released to production without impacting end users. These toggles are usually short-lived, and once the testing team has tested and verified the functionality, the development team can remove them from the codebase in a subsequent code deployment.

Release Toggle

Release toggles are an evolution of development toggles extending their lifetime past the initial release. They can control the rollout of a feature to specific users of the application for a canary-style release and roll back the feature if necessary. Release toggles are still relatively short-lived and are removed once the feature has been rolled out for all users.

Operational Toggle

Operational toggles have a more permanent lifetime and are used to switch to fallback features or implementation in the event of an application outage. Operational toggles can even be used to switch to a holding or maintenance page to inform users of a significant application issue.

Experimental Toggle

Experimental feature toggles are short-lived and designed for application users to enable updated or beta features. Once testing has been completed for the experimental feature, if successful, the toggle is converted to a development feature. However, when unsuccessful, the toggle is removed entirely along with the feature code.

Feature Toggles and Continuous Delivery

Feature toggles are critical in supporting an application’s continuous delivery process. Ensuring each build is deployable to production is fundamental for continuous delivery, which can only be achieved with a mechanism prohibiting incomplete or untested functionality from impacting the end users. Read more about continuous integration and delivery in our blog post on CI/CD.