Feature Flag / Feature Toggle

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.

Photo by John Smit on Unsplash

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.

services.AddFeatureManagement();

2. We write the names of our features in appsettings.json. Now we can use this file to toggle our features.

"FeatureManagement": {
"ExternalSystemIntegration": true,
"UseUtc": false,
"PreviewActive": true
}

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 IFeatureManager interface.

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 Now field.

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 Now field.

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.

--

--

--

var software = ConvertFrom(caffeine)

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

New in SwiftUI 3: Swipe Left or Right with SwiftUI 3

10 Confusing Yet Crucial Swift Functions

Smartphone on a sheer sheet.

Top Document Scanner Apps For iPhone And iPad In 2022 | Hyperlink InfoSystem

Access Control: Part 2

How to localize an iOS app programmatically (made easy)

Let’s Build Activity Ring in SwiftUI

SwiftUI Image: a closer look

AppStorage Property Wrapper SwiftUI

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adem Catamak

Adem Catamak

var software = ConvertFrom(caffeine)

More from Medium

Extend your .NET WCF codebase’s life expectancy with CoreWCF

Micro Frontends, Good, Bad or Ugly?

CQRS in a nutshell

Resource Oriented Architecture and Design