/
Tests

Feature flags / feature on/off switches

11. 12. 2022

Obsah článku

When developing a more complex application, you will appreciate the ability to develop more features up front, distribute them with the next version of your software, and enable the feature later.

This is exactly what feature flags were created for. This article will show you how to use them.

Basic implementation

Feature flags are basically a very simple concept of calling a single function/method that decides if a new feature is active.

For example:

echo '<h1>Weather apps</h1>';
echo 'Today it is:' . getWeather();
if (feature('map')) {
echo 'Map:' . getMap();
}

To check the availability of a particular news item, the feature() function is called, which decides whether it can allow or ignore the particular feature based on the call name.

Implementation of the decision logic

Decision logic is often complex. For example, you can only run a specific function from a specific date, or for users in a specific group. For example, I often test the deployment of a new feature on, say, 5% of users in this way so that it doesn't affect everyone at once.

For example, when developing corporate sotfware, this is how we run advertising campaigns and discounts that are valid from a certain date.

If a particular new feature breaks, it is possible to simply disable it with a feature flag for users, and enable it for a group of developers who will test it and bring a fix, for example.

Jan Barášek   Více o autorovi

Autor článku pracuje jako seniorní vývojář a software architekt v Praze. Navrhuje a spravuje velké webové aplikace, které znáte a používáte. Od roku 2009 nabral bohaté zkušenosti, které tímto webem předává dál.

Rád vám pomůžu:

Související články

1.
2.