How to Use Feature Flags

“Flags allow us to restrict features to certain environments, while still using the same code base on all servers.” ~ Ross Harmes

Feature flags offer an alternative to maintaining multiple various branches of source code. Continuous deployment requires such feature branches to be integrated with the master branch as early as possible. Feature flags are toggles that allow for early integration with execution paths turned off by a toggle that can be turned on for specific users/testers or when the feature is ready for deployment without having to roll out new source code. There are two basic types of feature flags: release toggles and business toggles. Release toggles are used for rolling out new features in continuous deployment. Business toggles allow for restricted user access such as through premium accounts. The simplest feature flags are boolean statements however they can be more. State can be set statically or dynamically. Rule based toggles can be used with XML, YAML, and JSON. Beyond common usage they are also available for trial of new features to allow early access to beta testers, allow internal review of the feature, or run A/B tests. When rolling out new features toggles can be used to verify scalability of the feature or app. Toggles should show a minimal presence in code and be retired once pending features are added. Dangers of using feature flags include accidental exposure of the feature, corrupting data, and technical debt created by the toggles.

Episode Breakdown

  • 10:55 What are Feature Flags

    “The basic idea is to have a configuration file that defines a bunch of toggles for various features you have pending. The running application then uses these toggles in order to decide whether or not to show the new feature.” ~ Martin Fowler

    Feature flags also known as toggles are switches in code that grant or deny access to different features of an app. They make it so that features in development or testing can be part of the overall app without making into the end user experience.

  • 13:27 Types of Feature Flags

  • Feature flags can be divided into two basic categories; release toggles and business toggles. Release toggles are used when a new feature is under development or to roll out or roll in features. Business toggles restrict user access to areas of an app and can be based on user experience or payed accounts.

  • 16:16 7 Lesser Known Uses of Feature Flags

    1. More than Just Boolean Statements

      Toggle state can be set statically or dynamically. Flags can be rule based toggles using XML, YAML, or JSON to define conditions for flipping the toggle.

    2. Enable Features for Specific Users

      In more long term usage feature flags can enable paygate or opt in options. They also allow unruly users to be blocked or restrict access based upon user experience level.

    3. Trial of New Features for a Sample Set

      Toggles allow for split or A/B testing and give the opportunity for early access to certain users. They can also be helpful when beta testing new features to allow users to opt in to the beta version.

    4. Internal Review of Features

      GitHub is a prime example of the use of internal review with their “staff mode” allowing staff access to features not yet in deployment. This allows the team to give feedback of the feature as it behaves in production.

    5. Scalable Roll Outs

      Scalability becomes an issue when rolling out new features. Toggles allow for phased roll outs to identify issues in scaling the feature.

    6. Maintenance

      Kill switches allow for features to be rolled back if issues arrise. Toggles may also be used to create a maintenance mode for updates and bug fixes.

    7. Sunset Old Features

      The prime way to do this is to toggle the feature off for any new users then slowly transition the current users to the new feature. Cell phone companies do this when changing their plans. When switching from free data to pay for data with limits many companies allowed existing customers to maintain their free data plans until they upgraded.

  • 35:50 Tips and Tricks

    • Maintain a minimum presence of toggles to ensure the feature is properly hidden.

      Too many toggles complicates code and creates tight dependencies. If creating and maintaining toggle points takes a significant amount of time the code may have too many toggle tests. To reduce this focus on the entry points such as log-in or sessions.

    • Retire release toggles once the pending feature is added.

      Not retiring toggles results in a pile of toggles noone knows how to use or if they are even in use. Remove the definition on the config file and all code using the retired toggle.

    • Make release toggles a last option.

      It is best to break down features to introduce parts of them into the production code. When that is not possible build the feature minus the UI entry point. Then add the UI in a single release cycle. The problem with this is that it makes testing the UI in production impossible until it is added.

    • Release toggles need to be short-lived.

      The purpose of release toggles is to reduce the risk when releasing new features. Once the release is complete the toggle should be removed.

  • 46:14 Dangers of Use

    Caution should be taken when using feature flags in production code. Toggles create technical debt, especially release toggles that need to be removed once the feature is complete. Being integrated into the production code untested new features may corrupt data used by existing features. Most dangerous is the possibility of accidental exposure of unfinished features or granting administrative access to users.


Single Cue is a touch free gesture control device for smart homes that allows control of your TV, media, and smart home. Use Voice, presence, or gestures to create a futuristic experience in your own home. Looks like a kinect designed for use in smart home. It contains a low light sensor with a range up to 16 feet, an infrared transmitter, bluetooth, and wi-fi.

Tricks of the Trade

The idea that you need more than one reason to do something can be a dangerous sign that you may not want to do it or shouldn’t do it. A lot of times when you are coming up with multiple reasons to do something it’s not because there are multiple good reasons but because there is not a good reason. If you are coming up with a litany of reasons sit back and askif you are coming up with excuses.

Editor’s Notes:

Tagged with: , , , , , , , , , , , , , , , , , , , , , , , , ,