71 views
Guide to Feature Flags
What are feature flags?
Feature flags allow developers to have more granular control of the features being released. It can be in a form of toggling a certain feature, enabling or disabling them. This is usually done with developers wrapping code around a particular feature.
Feature flags also help to reduce the risk of complicating the code base with potential conflicts.
An example would be a feature branch being worked on for a long time while the main branch was constantly updated with other features simultaneously. This could cause a possibility of a merge conflict when the stale branch gets merged.
As such, the feature flag allows us to frequently merge the changes while the feature is disabled when deployment into production is done.
Conducting experiments
Since feature flags can act as an "on/off" switch, A/B testing can be done easily to divide the traffic into different variants of the feature. Google Optimize offers A/B testing features to help with this.
How to create a feature flag?
Based on different requirements, there are many ways to create a feature flag. The following code is one example of how we can easily implement JavaScript.
FEATURE_FLAG_NEW_FEATURE=true
FEATURE_FLAG_NEW_FEATURE=false
if (process.env.FEATURE_FLAG_NEW_FEATURE === "true") {
// Some cool features here
} else {
// Some alternate features here
}
From the above example, we used the process.env
environment variables to control a particular feature.
Conclusion
Feature flags are very powerful to give teams and especially developers more control of the features being released and in turn more control over the UX of a product.