What is a “feature flag”?

后端 未结 12 573
天涯浪人
天涯浪人 2020-11-30 17:32

High Scalability mentions feature flags here:

5 things toxic to scalability, \"5. Lack of Feature Flags\"

What exactly are feature flags?

相关标签:
12条回答
  • 2020-11-30 18:07

    At my company we used to have an own solution for that. We created a service providing a downloadable config (.json) file for every apps. In that config we stored the flags for the features. Based on that config the app can show or hide the current feature. (For example show or hide a menu item on the sidebar).

    We also created an internal admin page where we can configure the feature-flags. It worked quite good for a while but after that we would have liked to do user targeting and A/B testing. To develop by own It seemed too much effort, so we chose a third-party solution. As already mentioned here there are many solutions for that.

    We chose ConfigCat because it supports customized target groups and percentage-based rollout at once. You can check the supported open-source sdks on github.

    0 讨论(0)
  • 2020-11-30 18:09

    There are a lot of great answers here, all driving at the important, basic definition popularized in the Martin Fowler post:

    They're bits of code that "[allow] teams to modify system behavior without changing code."

    So we've historically thought of them as represented by the pseudo-code:

    if(app_settings["beta-mode"] == "true")
      showAwesomeNewGui();
    else
      sameOldSnoozeFeset();
    

    That's a totally accurate way to think of it, and both Matt and Adil expand on it nicely with a variety of tactical use cases for the feature flag.

    But I'd like to offer a revised definition that reflects how reality has evolved in the six years and change since dotnetdev asked the original question. I work for Rollout.io, a feature flag platform, so I've had a front-row seat for this evolution.

    Simply put, feature flags aren't any longer just a way to turn bits of functionality on and off in your application. That's like answering "what is an invoice line item" by saying "it's a description and an amount of currency." True, but it doesn't drive at the broader point of the invoice itself.

    Feature flags are the tactical bits of an overarching strategic solution in modern software. They're the means by which you defer important decision logic in your code until runtime when you have more information. And, perhaps most importantly, they don't just occur in isolation any longer, with a single check to see if the version number is greater than 2.7 or not; organizations that use them are typically including them as part of a comprehensive, system-wide product approach.

    As others have mentioned, Facebook and LinkedIn pioneered this, but in 2018, a whole lot of organizations are doing it. They're deferring decision logic questions for runtime as part of development strategy, operations strategy (or DevOps strategy, if you want), and product strategy. Here are examples of such questions.

    • Who should see the new admin screen that we're rolling out, and when?
    • What level of membership is required to unlock this Easter egg?
    • When should we cutover to the new database?
    • Should we put a picture of a cheetah or an eagle on the checkout button to enhance conversions?

    To have an application that defers a significant number of such decisions until runtime, you can't throw feature flags into your application in ad-hoc fashion or you'll bury yourself in technical debt. You need, these days, to have a comprehensive feature flag management strategy, which includes a few different components.

    • Toggle points are used to switch behavior for new features.
    • Multiple toggle points come together to form a toggle router. A toggle router determines the state of a feature.
    • Toggle context provides the toggle router the necessary contextual information (e.g., specific user).
    • Toggle configuration provides the toggle router information about the environment.

    So, in the end, what are feature flags?

    Well, they're an important part of a broader strategy to having an application that's adaptable to both technical and market needs.

    0 讨论(0)
  • 2020-11-30 18:10

    From a coding point of view a feature flag can be as simple as an if statement which wraps around a new piece of code which you are writing. When the if statement evaluates to true (the feature flag is on) then the new code will be executed.

    In a real-world example of delivering software, the if statement described above would evaluate differently depending on environment the software is running in. For example if the application is being executed on your QA server the feature flag will return true and the new feature will be seen. If it's being executed on your production server the feature flag will return false and the feature will be hidden.

    From my personal experience during my career I have used feature flags in the following ways:

    1. Decoupling code deployments from releasing of features to customers. This was my first initial use of feature flags in our development process. We used it to remove the dependency between our marketing and product team and the engineering team that was doing the development and releases. Feature flags allowed us to deploy our code weeks in advance of a launch whereas previously we were deploying code the night before a release!

    2. Testing in production. Before we used feature flags when we released our code it was an all or nothing event, either all our customers got the feature or none of them did. We used feature flags to allow us to roll out a new feature to a small percentage of the users at a time. This allowed us to collect valuable feedback and data about a new feature without risking any potential issues to the entire customer base.

    3. Enabling/disabling a feature per environment in the development life-cycle. We used this extensively in development for allowing a much smoother deployment process - we have a CI/CD pipeline in which the use of feature flags is vital.

    4. Creating a kill switch. We have wrapped certain features of our application with a feature flag which allows us to 'kill' that feature in the event of any issues we are having with the application at the time. For example if we find ourselves under heavy load we are able to turn off certain non-essential features of the website to help with the issue.

    You can read more about feature flags here.

    You can add feature flags to your code in multiple ways.

    1. You can create your own or use a third-party feature flag library and add your feature flag data into a config file which can be included in your deployment package.
    2. You can create your own or use a third-party feature flag library and add your feature flag data into a config file which can be loaded at run-time.
    3. You can use a cloud-based feature flag management service to manage all your feature flag needs for you.

    Writing your own library may seem a good idea at first and usually it can start out that way. However you can soon run into issues when you want to implement the more advanced use cases of feature flags like rolling out to a percentage of users or targeting specific user groups. Another issue with creating your own feature flag implementation is if you are using multiple languages you will need to implement your code multiple times.

    The best and easiest way to use feature flags is to use an online feature flag management service such as Floodgate. This way you can leverage on the platform to all the heavy lifting which then allows you to concentrate on creating the feature for your application.

    Here is an example of how to add a Floodgate feature flag to an application using the .NET SDK.

    using FloodGate.SDK;
    
    var floodgateClient = new FloodGateClient("API-KEY");
    
    var flag = floodgateClient.GetValue("a-new-feature", false);
    
    if (flag)
    {
      // Execute the code for my new feature here...
    }
    

    If you are working in a development team and you are not using feature flags and you are experiencing issues in deployments and code management within the team. Using feature flags can be a great way to resolve these issues. There is also a nice side effect of feature flags speeding up your teams development velocity.

    Martin Fowler gives a very in-depth write-up of feature flags here which I recommend you to read.

    0 讨论(0)
  • 2020-11-30 18:11

    My understanding is that feature flags help you gate functionality by deciding which users receive certain features.

    For example, let's say you only want your beta users to see a new feature. You would "toggle" that feature on for beta users and the rest of your users would not see it.

    LDUser user = new LDUser("user@test.com");
    
    boolean showFeature = ldClient.toggle("your.feature.key", user, false);
    
    if (showFeature) {
         // application code to show the feature 
     }
    else {
         // the code to run if the feature is off
     }
    

    I'm testing LaunchDarkly's feature flags for some front-end JS A/B tests - seems to be working well. You can also check out this site for feature toggles and feature flag libraries.

    0 讨论(0)
  • 2020-11-30 18:12

    Feature Flag is a technique to turn some functionality of your application off, via configuration, without deploying new code.

    Feature flags play a key part in CI scheme where features are constantly being deployed but not necessarily "released" into production.

    More info here:

    • http://code.flickr.com/blog/2009/12/02/flipping-out/

    -- EDIT:

    Feature Flags java implementation.

    0 讨论(0)
  • 2020-11-30 18:12

    Feature flags (or feature toggles) allow you to enable features remotely on an application without needing to re-build/re-deploy the application. This allows you to deploy the code to production but not release the feature until you are ready. You are able to target specific users, so you could enable a new feature to your beta users to test.

    At our company we've previously used LaunchDarkly and other suggestions from FeatureFlags.io. We've also tried to use Firebase's Remote config to try and make this work however we found it wasn't really fit for this purpose.

    We ended up developing our own version called Bullet Train, which we've open sourced. It combines both Feature Flags/Toggles and Remote Config.

    0 讨论(0)
提交回复
热议问题