Feature Flag

A feature flag is a mechanism that allows you to remotely turn on or turn off a feature in your app without having to change the code.

Feature Flag Glossary Userwell

Many apps would benefit from the ability to toggle whether a particular feature or functionality is active. This could be for product segmentation, A-B testing, bug management, or any number of reasons. However, if toggling these features requires code redeployment, it may become more trouble than it’s worth. This is where the feature flag comes in.

In this glossary definition, we define feature flags, describe how they can be useful, and explore their implementation.

What is a Feature Flag?

A feature flag, also known as a feature toggle, is a mechanism in your app that allows you to remotely turn on or off a feature or functionality in your application, without having to deploy new code. Feature flags open up many opportunities for your app, which would be otherwise inconvenient or impossible if you had to keep patching software just to turn something off.

The principal benefit of feature flags is in their ability to rapidly and efficiently toggle their associated features without having to roll back or modify production code.

The Four Main Uses of Feature Flags

There are many uses for feature flags, not just in product development, but also in testing, sales, and marketing. However, we can group these uses into four main categories:

1. Experimentation

One of the tools in the product development and marketing toolbox is A/B testing. Here, you give two groups of users different variations of the same product (hence A and B). You measure the performance of each variation, and whichever performs better is the version you’ll proceed with.

A/B testing is often an iterative process that tests individual features at a time. And in many cases, you might not even be testing on the entire user population. In that case, it would be therefore inconvenient to deploy different code to several separate groups. Feature flags allow you to bypass this problem and simply selectively enable or disable certain features for each group of testers. 

2. Operational Uses

Being able to modify product behavior easily, without deploying new code, has many operational uses during the product life cycle. 

For example, you can quickly and easily disable a feature that needs to be taken down for maintenance. This way, users won’t have access to something that isn’t functional, until it’s ready to go live once more. Similarly, you can turn off access to a feature that is experiencing a bug or a service outage, to prevent a negative user experience.

In many cases, it may be better for a user to have fewer features than to have a bad experience at all. One example is turning off features that are experiencing heavy loads and reduced performance. A feature toggle will let you turn off such a feature and replace it with something less complex until you can fix the problem.

3. Release Management

Traditionally, you finish developing a new or updated feature on a separate branch, before patching it into production code. As production code evolves, this can become unwieldy, given that you’ll have to keep updating and merging the development branch to ensure compatibility.

But with feature flags, developers can work on new features within the same codebase, while making sure that their work is not visible to end-users. This helps improve efficiency and speeds up the development of new features. It’s a highly valuable asset to continuous development.

4. User Segmentation

Because feature flags can selectively enable access to features, they play a valuable role in SaaS and user access control.

For SaaS, imagine a product that segments its features based on a subscription tier. Free accounts only get access to a tiny subset of the main product features. In turn, Premium and Pro users get increasingly wider selections of features. In this scenario, the developer uses feature flags to selectively activate features for each subscription tier.

You can see a similar approach in enterprise products that feature user access control. For security purposes, you may need certain users to have limited access to company resources and software features. For example, only administrators will be allowed to access an admin panel from their profile page. You can use feature flags to selectively grant access to these features based on user account type.

How Do You Implement Feature Flags?

When a feature is being developed with feature flag functionality in mind, developers take certain steps to implement it.

First, they contain the code within a conditional statement. That statement describes whether the feature is available for use or is visible to users.

In pseudocode, this might look like:

if(userHasNewFeature === true) {
newFeature();
}

In this case, “userHasNewFeature” is the feature flag, essentially an IF statement that is either true or false. Below it, newFeature is the feature being controlled.

After this, developers will set userHasNewFeature to be remotely togglable, for example from a dashboard or API, or triggered by certain rules. That way, it becomes possible to toggle the functionality of the newFeature without changing any code at all.

Feature Flags: Easy to Implement When New, Hard to Do After the Fact

When should you implement feature flags? In general, it’s a safe bet to ask this question during the development of every major user story and requirement. This is because it’s difficult to apply a feature flag once a feature is completed without it. 

So, in short, you should make sure that consideration of feature flags is a part of your product development process from the outset, especially if you’re working in an agile, continuous delivery environment, or have encountered any of the use cases we discussed above.