2 min read

Feature flags are useful to control how the way we enable and disable features

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.

if (process.env.FEATURE_FLAG_NEW_FEATURE === "true") {
	// Some cool features here

From the above example, we used the process.env environment variables to control a particular feature.

This screenshot shows that the feature flag has been enabled during development and I was able to work on the Featured Posts.

Feature flag enabled on development

This screenshot shows that the feature flag has been disabled on production such that the code does get deployed and existed but just does not show up since I was not ready with the release of the Featured Posts.

Feature flag disabled on production


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.