What are feature flags?

Feature flags (also known as feature toggles or feature switches) are a software development technique that turns certain functionality on and off during runtime, without deploying new code. This allows for better control and more experimentation over the full lifecycle of features.

The idea behind feature flags is to build conditional feature branches into code in order to make logic available only to certain groups of users at a time. If the flag is “on,” new code is executed, if the flag is “off,” the code is skipped.

Also referred to as or release toggles, feature flags are a best practice in DevOps, often occurring within distributed version control systems.

Feature flag use cases & benefits

There are many benefits for incorporating feature toggles into your release process. The following are some common use cases:

Testing in production

Feature flags allow development teams to test new features in production, while mitigating the risk of a poor release by providing a way to quickly roll back the feature if necessary via a kill switch. Because it is often impossible to completely simulate the production environment in staging, feature toggles allow you to validate the functionality of new feature releases in the real world while minimizing the risk. Feature flags also encourage trunk-based development, which helps prevent merge conflicts from divergent code paths.

Canary releases

Another use case for feature toggles is allowing a team to test a new feature on a subgroup of end users to see how it performs before rolling it out to a broader audience. Canary testing helps to limit the risk of launching a feature to your full user base, and allows you to quickly roll back a feature simply by toggling it on or off, rather than having to go through another deploy cycle.

Quicker release cycles

Using feature flags, a team can modify a system’s behavior without making disruptive code changes to the live code. Thus, one major benefit of feature flags is their simplicity to deploy in the development process. Feature flags decouple feature lifecycle management from code deployment, freeing up the engineering team to work on other tasks.

Rollback / kill switch

Enabling or disabling new features using feature flags is as easy as toggling it on or off or editing a config file vs having to re-deploy and having to go through a lengthy code push. If a bug is discovered in a new feature, it can be rolled back instantly without having to touch your source code. This can be especially powerful for mobile app developers, who can use feature flags to release or roll back new features without having to go through the length app store review process.

Server-side A/B Testing

Developers can implement A/B tests, using feature flags by enabling a feature for half of a segment of users, and disabling the feature for the other half, and seeing how the two perform against each other for a certain metric (such as app usage or purchases). Because the test is implemented in the backend through code, there is no latency, compared to what one might experience with a test implemented via client-side JavaScript.

Feature flags also allow product managers and other non-engineers to A/B test various features within products or systems with no need for a code deployment. Tests can also be targeted at specific segments of your userbase as well, for example users that live in a specific country or fit a specific user profile. Leading tech companies such as Google, Facebook, Amazon and Netflix frequently A/B test new features before deploying to their full user base.

Feature gating

Feature flags can be used to implement targeted rollouts of features to a specific subset of your users. This can be great for A/B testing features with specific segments of your audience, but it can also be used to release features to only a subset of your users, for example granting users in your enterprise tier access to features that aren't available in lower tiers. Implementing feature gating using flags allows you to easily rollout features to more of your users in the future as your product evolves.

Continuous deployment

Another major benefit is of feature flags are their ability to allow quick learning. Feature flagging allows companies to continuously deliver and deploy software to their users in a faster way. The use of feature flags allows companies to perform gradual feature rollouts, fix bugs in the code without redeploying, experience a more streamlined development cycle and do rollbacks of code more easily.

Feature flag development process

Implementing feature flags in your code doesn't have to be a complicated process. With a feature flag service such as Optimizely, all you need to do is install the SDK, create the flags within the feature flag platform, and then wrap new features or code paths in your code within the flags.

That's all it takes to enable feature flags, and now the new feature can be toggled on or off via a configuration file, or even via a visual interface within the feature flagging platform. This can enable non-technical users, such as product managers, to run experiments on new features or turn off features, without having to rely solely on the development team.

Once feature flags are live, another important consideration is feature flag management. To avoid the technical debt of having feature flags remain in the code after they have served their purpose, it is important to review flags at a regular cadence and remove ones that are no longer necessary. This process can be automated within many feature flagging platforms.

Feature flags & continuous delivery

Championed by influential software developer Martin Fowler, continuous delivery is a software development discipline in which software can be released to production at any time. It has been adopted by leading software companies around the world whose teams are now expected to quickly deliver software that is stable and bug-free to your user base.

Feature flagging enhances CI/CD by making “continuous” more achievable. The feature flags and feature toggles are a key component of the implementation of continuous delivery, allowing the separation of feature rollout from code deployment. Incomplete features can be merged into the production codebase but hidden behind feature flags.

With continuous delivery and feature flag management, a team can launch, control, and measure their features at scale.

Feature flags in Optimizely

Product and engineering teams can now use Optimizely Full Stack’s feature management to implement feature flags. This allows the same flexibility that product teams have relied on with their experimentation programs to validate hypotheses before launching new products, features, and experiences to everyone.

Now this experimentation can work seamlessly with the practices of continuous integration and continuous delivery employed by today’s advanced engineering teams. Both teams – and entire companies – will be able to benefit from the faster development cycles, and feature management practices like flags or toggles to mitigate risk.

Optimizely server-side experimentation customers can follow in the footsteps of the world’s top software companies (like Amazon, Google and Facebook) to develop their user experiences, A/B testing to find the best experience possible, then using feature flags to control the rollout.

By first running A/B tests to a small segment of traffic, any team can determine the best version of a new feature, or measure whether the new feature is truly an improvement.

Optimizely also offers free feature flags through Optimizely Rollouts, a completely free solution (unlike competitors like LaunchDarkly) for controlled feature releases in your product or app. Rollouts offers a number of SDKs on Github for some of the most popular programming languages and frameworks including Node, Python, Ruby, Go, React, Swift and C#.