DEV Community

loading...

Feature toggle/flag

vikrampawar
・1 min read

It's the idea of having a bunch of ifstatements in your code to turn a new feature 'on' or 'off'. It sounds a bit crazy when we put it that way, but it has a useful function.

This technique is used to push a new feature to production and test it by turning the feature 'on' for a small subset of your users. This is used in continuous delivery environments to deliver code to production as soon as it's ready, but at the same time reduce the impact if it doesn't work as expected, or, has a bug that can manifest only in production environment.

Once you gain confidence that the feature is working for the small subset of users, you gradually expose other users to the feature.

A slightly more advanced version of this was done by GitHub. They built a tool called Scientist which allowed them to compare the output of the new feature against the output of the existing feature and log the difference, but use the old feature to serve the user for now. Later, they went through the log to understand if the differences seen were expected ones or not. After seeing a sufficient number of these logs, and when their confidence in the new feature was established, they turned this feature 'on' for everybody.

Discussion (0)