3 minute read

Feature toggles, sup?

What is a feature toggle? It is often the use of conditional logic to trigger certain functionality for the user. In most examples, the pseudo code goes something like this:

if(featureFlag) specialLogic();
else regularLogic();

So, what’s all the hubbub about this simple concept?

Well, simple as it sounds, there is a lot of complexity that can and often arise.

  • Code changes are being made to support toggling that may or may not be related to your actual business
  • Overlap of toggles in the code can lead to lots of unexpected interactions as well as exponentially multiplying cases to test
  • Requires some form of persistence that will need to be secured (flat file or dB record)
  • Can allow for potential security breaches by shipping code that may or may not be fully complete
  • Configurations can be mistakenly set up

At this point, you may be saying - “well, genius, Facebook, Google, Spotify, etc use them. They can’t all be wrong, can they?” But in order to address the actual issues, we have to talk about the exact use cases of feature toggles.

Let’s define things!

Feature toggles need to be defined by their use. From where I stand, there are a few main cases:

  • Product feature toggle (I.e. premium features)
  • Setting configuration (preferences, locale)
  • Incomplete features

The first two cases make a lot of sense. Those are business decisions that are required to support a sales/delivery model.

Product features: may be only provided to a user if they have some special privilege or agreement with the provider. The often cited example is a premium feature or privilege. In mobile games that follow the f2p model, it’s not uncommon to unlock special 1-time power ups with money or in-game currency.

premium

Setting configuration: used for product-level customization such as white-labelling (a.k.a. theming), language support, user preferences. One example that comes to mind, which may not apply as well, is the different race selection in the popular rts game, Starcraft 2. In-game, the user can select which race they play as. The game is, in essence, the same. However, the experience and the nuance is different. This is the sort of configuration that’s more of a setting.

config

Incomplete features: this option for feature toggles is often used when merge conflicts are a scary thing (which they more or less always are) and the need to have continuous integration of code in the main branch is important. The not-so-obvious reality of using feature toggles in this way is that teams are often shipping incomplete, buggy, and unsafe code into production. Even though access to the endpoints should be locked down, there is always room for error.

config

The actual problem

Now that we have sufficient background, let’s get back to business. The original problem was suggested to my team as a question:

should we or should we not be using feature toggles?

They continued, “We believe we have different features that may compete with one another/are mutually exclusive, so we think we need feature toggles.”

After some more probing, we uncovered the root cause: the team has multiple streams of work and they’re actually looking to avoid merge conflicts and allow for integration to begin earlier. Doesn’t that sound like it matches one of the criteria for feature toggles?

hint: Incomplete features

The pivot

If you’re wary of these sorts of situations, you might get some uncomfortable itch after reading those few lines. It sounds a lot like the XY Problem. For the unfamiliar:

The XY problem is asking about your attempted solution rather than your actual problem - Stack Exchange

Given the context, the team doesn’t really even need feature toggles. What they do need is a better way/process of slicing up and portioning work, in order to always be able to complete them in incremental portions. Not being able to merge large chunks of work due to code conflicts are more a symptom of a process problem and rarely ever a coding problem. In a sense, seeking the usage of feature toggles for these sorts of situations almost seems like an easy way out of dealing with the underyling issue.

Anyway, there’s my foray into feature toggles. For real code examples, click here!