Feature Flags with FeatureToggle

存储架构 2018-02-15

Feature Flags is useful method to integrate rapidly new functionality, finished or unfinished, into the product. But there are also some traps.

There are different categories of Feature Flags:

  • Release Flags

Release flags are enabled or disabled by deployment and are typically used for the features which are still in-progress. The longevity of Release Flags should be between days and weeks.

  • Experiment Flags

Typically, Experiment Flags are used for A/B tests. They are dynamic and are enabled or disabled for example by http request. The Experiment Flags can live in the code base between weeks and months.

  • Ops Flags

Ops Flags can be used by rolling out a new feature which can have a performance implications on existing application. Ops Flags allow to enable or disable the feature by run-time reconfiguration. They can have longevity between months and years.

  • Permission Flags

Permission Flags can stay in the code base forever. They are used to enable or disable features for only certain users.

When you create new functionality it is common to create a new branch. This is fine when the new feature is integrated into production code very soon, in the best case next release, like the feature/x
in the picture below. But what will happen to the code when the feature/y
will not make into the production by next release? The longer it takes to, the higher the risk of merge conflicts. But there is more: costly integration and delayed feedback can rise a risk to deliver poor quality.

With the Feature Flags you can integrate as often as possible, than Feature Flags allows you to deliver also unfinished functionality. This make possible to test the code and the functionality continuously and at very arly stage.
Unfortunately the Feature Flags can create some very serious problems
if implemented and deployed improperly and have some disadvantages like:

  • Temporary code base noise
  • Risk of leaky code/feature
  • Necessary code changes by removing the flags
  • Increasing code, test, integration and operation complexity

Feature Flags with FeatureToggle

This example show how to use Feature Flags with FeatureToggle Framework
in the ASP.NET Application. The purpose of the application is to track To-do’s. The design is very simple.

In this example is the value of the Feature Flag persisted in the database table ApplicationFeatureFlags
.

CREATE TABLE [dbo].[ApplicationFeatureFlags] (
 [Id] INT IDENTITY (1, 1) NOT NULL,
 [Name] NVARCHAR (MAX) NOT NULL,
 [IsEnabled] BIT NOT NULL
);

The table contains only singe entity IsCompletedFeatureFlag
.


To get the value of Feature Flag from the database SqlFeatureToggle
class is used. New class which represent the Feature Flag self is created and inherits from the SqlFeatureToggle
class.

namespace ToDoApp.Common.Features
{
    using FeatureToggle;

    public class IsCompletedFeatureFlag : SqlFeatureToggle { }
}

The IsCompletedFeatureFlag
class is used as a property in Todo
model.

namespace ToDoApp.Common.Models
{
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using Features;
    using Newtonsoft.Json;

    [JsonObject]
    public class Todo
    {
        [DefaultValue(false)]
        [Required]
        [DisplayName("Completed")]
        [JsonProperty]
        public bool IsCompleted { get; set; }

        [Required]
        [JsonProperty]
        public string Description { get; set; }

        [JsonProperty]
        public int Id { get; set; }

        public IsCompletedFeatureFlag CompletedFeature() => new IsCompletedFeatureFlag();
    }
}

In the TodoIndex.cshtml
view are certain controls rendered only if the CompletedFeature
is enabled.

@if (item.CompletedFeature().FeatureEnabled)
{
    
      @Html.DisplayFor(modelItem => item.IsCompleted)
    
}

There is one important thing to do. To be able to SqlFeatureToggle
to get data from the database there is need to have a connection string or connection string name and select statement defined in the web.config.

To be able to manipulate the IsCompletedFeatureFlag
there is also a applicationfeatureflag
REST API Endpoint. Just call /swagger
on API to see all available methods. There is also UI to manipulate the Feature Flag as you can see below.

One notice on the design. You will not probably want to use the FeatureToggle as describe above as this is only very naive implementation to keep the sample easy. Better approach will be to get the flags value over the API. FeatureToggle Framework allow you to implement your own custom logic
. There is also great Pluralsight course on FeatureToggle’s
.

Sourcecode

https://github.com/kalcik/blog-samples/tree/master/Feature_Flags_with_FeatureToggle/src/ToDoAppSolution

Cite Sources

1
Hodgson Pete, “Feature Toggles (aka Feature Flags)”, Martin Fowler (blog), 09. October 2017, https://martinfowler.com/articles/feature-toggles.html

责编内容by:Anton Kalcik (源链)。感谢您的支持!

您可能感兴趣的

亚马逊、Salesforce 正开发自己的数据库以摆脱 Oracle... Information 近日报道称,在 2017 年 12 月中旬的甲骨文盈收电话会议上,华尔街的一位分析师问道,是否已有数据库客户在转向低成本的替代品。 甲骨文公司联合创始人 Larry Ellison 回应称其庞大的 500 强客户群并没有出现迁移。其两大客户巨头 Amazon 还在继续购买 ...
去中心化数据库:传统IT与区块链的未来融合形式... 前言:区块链从概念诞生到技术发展已经历较长时间,但是随着这两年的火热,才渐渐被市场和许多技术人员了解。作为一个数据库行业的老兵,巨杉数据库联合创始人兼CTO王涛看到传统的IT技术同学们对于在热潮之下的区块链技术,保持了十分理性,甚至是排斥的态度。 在本文中,王涛将从数据库对比的角度,帮助传...
某涉密单位数据库审计联动运维审计应用实例... 摘要: 在大数据时代的战场上,数据就是激活体系的血液。如何确保海量信息数据的安全,已经成为维护国家安全的核心命题。在此背景下,本文深入探讨了首次将数据库审计与运维审计联动阻断落地于某涉密单位的项目实例。 客户简介 该涉密单位核心业务大数据系统集成了多种数据库类型,如... 在大数据时...
揭秘地下’se’情’诱’导网站,上车吧!... 1、意外发现 前阵子有朋友在追美剧《权7》,所以偶尔会拖我找资源:"你有权7的资源没有?" "帮忙找下熟'肉?" 虽然我一直吐槽"自己不会去开个会员或者百度/谷歌找?" 不过又想了想,对于非技术圈的朋友,很多人总是这样来思考: 网上资源再丰富,百度谷歌再牛,也没有比自己身边"修电脑"的朋友...
DBAs and the ITIL Framework, Part II: Asset Manage... This article follows onto my previous article DBAs and the ITIL Framework . My first article dealt with ITIL from an event and services management...