Feature toggle explained

A feature toggle in software development provides an alternative to maintaining multiple feature branches in source code. A condition within the code enables or disables a feature during runtime. In agile settings the toggle is used in production, to switch on the feature on demand, for some or all the users. Thus, feature toggles do make it easier to release often. Advanced roll out strategies such as canary roll out and A/B testing are easier to handle.[1]

Continuous delivery is supported by feature toggles, even if new releases are not deployed to production continuously. The feature is integrated into the main branch even before it is completed. The version is deployed into a test environment once, the toggle allows to turn the feature on, and test it. Software integration cycles get shorter, and a version ready to go to production can be provided.[2]

The third use of the technique is to allow developers to release a version of a product that has unfinished features. These unfinished features are hidden (toggled) so that they do not appear in the user interface. There is less effort to merge features into and out of the productive branch, and hence allows many small incremental versions of software.[3]

A feature toggle is also called feature switch, feature flag, feature gate, feature flipper, or conditional feature.

Implementation

Feature toggles are essentially variables that are used inside conditional statements. Therefore, the blocks inside these conditional statements can be toggled 'on or off' depending on the value of the feature toggle. This allows developers to control the flow of their software and bypass features that are not ready for deployment. A block of code behind a runtime variable is usually still present and can be conditionally executed, sometimes within the same application lifecycle; a block of code behind a preprocessor directive or commented out would not be executable. A feature flag approach could use any of these methods to separate code paths in different phases of development.

The main usage of feature toggles is to avoid conflict that can arise when merging changes in software at the last moment before release, although this can lead to toggle debt. Toggle debt arises due to the dead code present in software after a feature has been toggled on permanently and produces overhead. This portion of the code has to be removed carefully as to not disturb other parts of the code.

There are two main types of feature toggle. One is a release toggle, which the developer determines to either keep or remove before a product release depending on its working. The other is a business toggle, which is kept because it satisfies a different usage compared to that of the older code.

Feature toggles can be used in the following scenarios:

Feature toggles can be stored as:[4]

Feature groups

Feature groups consist of feature toggles that work together. This allows the developer to easily manage a set of related toggles.[5]

Canary release

A canary release (or canary launch or canary deployment) allows developers to have features incrementally tested by a small set of developers. Feature flags like an alternate way to do canary launches[6] and allow targeting by geographic locations or even user attributes.[7] If a feature's performance is not satisfactory, then it can be rolled back without any adverse effects.[8] It is named after the use of canaries to warn miners of toxic gases (Miner's canary).

Adoption

Martin Fowler states that a feature toggle "should be your last choice when you're dealing with putting features into production". Instead, it is best to break the feature into smaller parts that each can be implemented and safely introduced into the released product without causing other problems.[9]

Feature-toggling is used by many large websites including Flickr,[10] Disqus,[11] Etsy,[12] Reddit,[13] Gmail[14] and Netflix,[15] as well as software such as Google Chrome Canary.

See also

Notes and References

  1. Web site: ALM Rangers - Software Development with Feature Toggles. msdn.microsoft.com.
  2. https://www.infoq.com/news/2021/05/github-feature-flags/ How GitHub Leverages Feature Flags to Ship Quickly and Safely
  3. Book: Programming JavaScript Applications. 2016-09-14. https://web.archive.org/web/20160915101514/http://chimera.labs.oreilly.com/books/1234000000262/ch09.html. 2016-09-15. dead.
  4. Book: Echagüe, Pato. Managing Feature Flags. O'Reilly Media. 2014. 9781492028598.
  5. Book: Elliot, Eric. Programming JavaScript Applications. O'Reilly Media. 2018.
  6. Web site: 2022-02-09 . How to do Canary Release / Progressive Delivery with ConfigCat ConfigCat Blog . 2022-12-22 . configcat.com . en.
  7. Web site: Canary Testing - Using Blue-Green Deployments and Feature Flags. 26 February 2021. unlaunch.io. 14 August 2021.
  8. Web site: Canary launches – how and why to canary release. 7 April 2015. launchdarkly.com. 9 January 2017.
  9. Web site: FeatureToggle. Martin Fowler 29 October 2010. 2010-10-29. Martinfowler.com. 2013-09-27.
  10. Web site: Flipping Out - code.flickr.com. Ross. Harmes. flickr.net. 9 January 2017.
  11. Web site: Partial Deployment with Feature Switches. July 9, 2010 . dcramer . 2013-10-10 . dead . https://web.archive.org/web/20131105232758/http://blog.disqus.com/post/789540337/partial-deployment-with-feature-switches . 2013-11-05 .
  12. Web site: How does Etsy manage development and operations?. 4 February 2011. codeascraft.com. 9 January 2017.
  13. Web site: reddit/reddit. github.com. 9 January 2017.
  14. Web site: Developing Gmail's new look. googleblog.com. 9 January 2017.
  15. Web site: Preparing the Netflix API for Deployment. netflix.com. 9 January 2017.