10

Feature flags are something I often use but never really gave much thought about it until this new project I'm working on started.

I usually implement it with lots of keys in my web.config file but this approach has two major drawbacks:

  1. When changing a value inside web.config the application pool is restarted - This can be a problem in a heavy access environment
  2. Having too many keys in the web.config file is confusing and can get pretty messy

What's the best way to overcome these problems?

Community
  • 1
  • 1
tucaz
  • 6,524
  • 6
  • 37
  • 60

3 Answers3

11

I would suggest using IoC to abstract away the implementation of your feature flags - all your code needs to access is something along the lines of IFeatures.IsEnabled("FeatureA"). Once you've done this, you can choose the most sensible implementation - some suggestions below:

  • web.config implementation (compatible with what you have now)
  • Database implementation (with cached values, possibly using SqlDependency if you want to work on a web farm)
  • Separate configuration file implementation (cached, but using a FileSystemWatcher to check for changes to the config file and load them without needing to restart the app pool). This allows for the case when you need features defined before you need your DB.
Richard
  • 29,854
  • 11
  • 77
  • 120
  • 6
    As a further tip, try to use enums instead of magic strings for flags. It's easier to locate where they're used when you want to clean them up or change their names, and Intellisense reminds people what flags have been defined, reducing the chances of people creating duplicates. – Richard Banks Oct 07 '13 at 23:34
5

You don't have to store feature flags in web.config.

An option is to store them in a database - this has the added benefit of working well in a web farm.

Note that with feature flags, once you are in a position that a feature will be either permanently on or off (say when transitioning from widgetA to widgetB, and you will no longer need any widgetA code), you should be removing the feature and associated flag. This will help with managing the feature set.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • you have right, is ask how to overcome that, not what I have type, so I delete it. (I just say to still use web.config that is something different) – Aristos Jan 22 '13 at 16:57
0

If you want add feature flags to your C# applications I would not recommend creating your own feature flag solution but rather to use one of the several feature-flag-as-a-service providers which are out there that can directly integrate with C# right out of the box.

One such solution is Floodgate which has an SDK for .Net which you can install and be up and running with using feature flags in your application in next to no time.

Disclaimer, my name is Eugene and I'm the founder of Floodgate. That being said my advice is the same no matter what feature flag provider you decide to use.

Eugene
  • 31
  • 1