Feature Flags

Feature flags, also known as feature switches or toggles, are actually quite simple. Essentially, they can be described as a Boolean value set to enable or disable certain features in a software application without the need to deploy new code. This mechanism not only adds flexibility to the development process but also significantly lowers the risks associated with deploying new features. In its simplest form, it could look like this:

if (resources.isEnabled()) {
   showResources();
}

Understanding Feature Flags

Imagine your team is using CI/CD with a main branch that should always be updated and ready for release. For every new feature, you create a feature branch from the main, work on it, and then merge it back into the main. These feature branches should have a short lifetime (preferably no more than one working day).

However, the development of a new feature may take days, weeks, or even months, and therefore, there will be unfinished functionality in the main branch when code is deployed to live environments. To hide this from end users, we can wrap it in a feature flag. This way, we can separate deployment from release and have control over the functionality that is not finished.

Advantages

By using feature flags, we achieve faster iterations and can experiment in live environments without much risk. For instance, it makes it possible to test functionality in the production environment without the risk of it breaking or users being affected by unforeseen errors.

Another advantage is that anyone on the team can turn the flag on and off. A developer is not needed to change functionality. It could just as well be switched by a consultant.

Less stress and risk at release is also an obvious advantage of using feature flags.

Where to put the flags

In general, you should try to place the feature flag as early as possible in the stack. The UI is obviously a good place as you can block user interactions. At the same time, it is important to consider security so that, for example, new endpoints are not left exposed when you don’t want them to be. Be mindful of security to avoid introducing vulnerabilities.

Try to avoid setting the same flag in many places down the stack, as this can quickly lead to unmanageable code and a lot of technical debt.

Managing Flag Debt

It is important to ensure flags do not become unused and accumulate as technical debt. A good rule of thumb is that no feature is finished until the flag is completely removed, both from the code and in the Feature Manager.

Conclusion

In conclusion, feature flags are a useful tool for enabling or disabling features at runtime. When implemented effectively, both in the codebase and in the feature management platform, they can significantly accelerate performance and reduce stress and risks associated with development teams.