Feature Flag / Feature Toggle
Manage application features without making code changes
Yazının Türkçe versiyonuna bu link ile ulaşabilirsiniz.
The feature flag is the name given to the technique that allows the workflow to change without making any changes to the code. Don’t be intimidated by the ‘technique’ in its definition. The basis of the work is based on the if-else condition known to all software developers.
Let’s talk about a few usage scenarios. By doing so, we can understand more easily in which situations the technique can be used and what benefits it provides us.
Imagine that you are developing a new feature. The marketing team will decide when to offer this feature to the end user. In this case, you can send your code to the production environment with the feature flag. The decision to activate this flag is now up to the marketing team. Therefore, you can focus on your next task. In short, you can use this technique to reduce the dependency between teams.
You can decide whether some features will be active or not based on information such as username or IP. In this way, you can enable a certain user group to access some features in the live environment. With this method, you can set the criteria in the feature flag according to your own user information and have the power to test in a live environment. Another usage is to present two different scenarios to users through feature flags and as a result being able to do A/B testing.
Note: The following keywords may be helpful to learn more about this topic: Feature Flag, Feature Toggle, Feature Switch, Feature Flipping
Usage of Feature Flag in .Net Projects
You can reach the sample project I prepared on GitHub.
We can easily implement this feature in .Net projects. For this, we can use the FeatureManagement library developed by Microsoft. This library returns information about whether the features are turned on or off via the keywords in the settings section. The library is very simple to use.
1. We start by introducing the dependencies to our system with the following line of code.
2. We write the names of our features in
appsettings.json. Now we can use this file to toggle our features.
3. We decide what our code flow is going to be like by learning whether the features are on or off using the
IsEnabledAsync method defined at the
Let’s take a look at the sample code snippet below. Let’s assume that our
UseUtc flag is
false in our settings file. In this case, when the following code block runs, we place the local time information in the
Thanks to the feature flag, we can change the flow of our code without making any changes to our code, releasing a new version or closing and opening our application. If we change the value of the
UseUtc field in the
appsettings.json file to
true, we can see the Utc value of the current time in the
You can access other services offered by the library for feature flag management via this link.
I hope it has been a useful post. You can click on this link to browse my other articles.