Moderate Fun with Feature Toggles


A Feature Toggle is just a way to enable of disable certain software features based on several criteria (configuration flag, time, user, some complex context,…).

The problem feature toggles try to solve is: how does one release code that is not totally finished without any apparent  impact on users. Let’s say your team is working on two features simultaneously, one large and one small, and we want to get the small one “out of the door” (that is, deployed to production) as soon as possible while disallowing users to operate the large, unfinished one.

This simplistic concept has made into the hotspot recently as the suggested alternative for feature branches in environments in which Continuous Integration/Delivery is dogmatically advocated.
And I say dogmatically because I have not been in the position in which a feature branch (in SCM) did not solve that problem while still being confident in the integrity of my build (safe-guarded by my CI server). It should be really easy to “clone” an existing build definition in the CI server into another one and listen to changes in a different branch. If it isn’t I think it might be time to change your CI Server instead of discarding features branches altogether.

As you can imagine I am pretty much against feature toggles as I believe they are the doorstep to happy feature branching in multiple places, with the corresponding readability/maintainability nightmare.
Having said so, feature toggles are just another tool that one needs to pull from the tool-belt when almost every other tool failed.

The Challenge in Hand

Big feature: almost a complete sprint.
Small surface of activation: it all starts with a scheduled tasks that perform a state transition on certain entities under certain conditions and everything else goes on from there. No task ⇒ whole feature is invisible.
No feature branch upfront: code is in trunk and it would be risky to fiddle with SCM to pick commits out.

Whoever validates the big feature as correct is on holiday and some other smaller features need to get to production.

A simple solution

Given the small activation surface, it makes sense to have a feature toggle that prevents the scheduled tasks from running and hence, the feature is virtually not there.

When the feature can be validated by the business owners, it will be enabled in configuration and eventually the toggle will disappear.

Some Implementation Details

Instead of rolling my own, I spent a couple of hours looking at what was already out there and I finally chose FeatureSwitcher. Why? I think we’ll wait for that until next post on the subject.