Feature flags in products

Photo by Arthur Mazi on Unsplash

Feature flags in products

·

2 min read

I had earlier heard about A/B testing, which is where we divide set of users into groups of A and B. Certain product behavior is observed only by group A and not by anyone from group B. In this way, companies are able to test features and get feedback from users before deploying to a wider audience in general availability.

Recently came across youtube video youtu.be/HvKL3rXVwfg?feature=shared, where the youtuber spoke about different kinds of feature flags - static, dynamic, customer-specific. It was a great video. I am going to summarize what I learnt from that video.

Feature flags are toggles which can be used by developers to modify the behavior of a product without the need for code modification or code redeployment. Let's say, you have certain features which are available as part of release. But, you can decide that, for some environment OR for some customer, that feature need to be disabled. You don't need to rewrite the code hardcoding with environment specific information or customer specific information. Instead you can control these via properties file, to start with. So, you can have a code block like below:


public void processOrders(){

if(Feature.isFeatureEnabled(feature1){
    processByFeature1();
}
else if(Feature.isFeatureEnabled(feature2){
    processByFeature2();
}

}
feature1:true
feature2:false

In code example above, using the Feature static class which can lookup properties file.

Until now, what we have seen, is that, this is a static feature flag.

You can make it dynamic by having a configuration server - a centralized configuration server. And you can make lookups from that server, but this adds a latency depending on the number of times lookups can happen and there is a question, whether you can cache these values or not.

public void processOrders(){

if(configServer.isFeatureEnabled(feature1){
    processByFeature1();
}
else if(configServer.isFeatureEnabled(feature2){
    processByFeature2();
}

}

You can also be customer specific enhancing the dynamic of feature flag:

public void processOrders(){

if(configServer.isFeatureEnabled(feature1, customer1){
    processByFeature1();
}
else if(configServer.isFeatureEnabled(feature2, customer1){
    processByFeature2();
}

}

When do we use a feature flag ?
If we want to do A/B testing.

If we want to control product launches, so that, during the product launches, the feature can be enabled.

If we want to control features during product versioning, we can toggle features for different versions. This means that the feature is actually present as code in previous versions, but not enabled.

Disadvantages:
It can introduce complexity in managing codebase, as there could be multiple feature flags which will determine the multiple code paths, we should be careful whether different paths are protected or not. Also, maintaining the codebase as and when the features are made GA, then the feature flags need to be cleaned up.