Let's imagine you want to experiment with different application settings and their impact on your customers. The solution you use should support an option to target specific users, and it should be easy to use for a product manager.
Theoretically, developers could deploy new code every time you want to check new settings. Unfortunately, this requires the time and involvement of many people.
You could, alternatively, create a place in the admin panel where specific values could be updated. The problem with that option is that many organizations have multiple applications, and implementing a separate admin panel in each of them isn’t ideal.
What are your other alternatives? Are there any proven solutions in the software development world? Yes—they’re called feature flags.
Feature flags are part of a software development technique that gives you the ability to turn certain functionality on or off, without deploying new code.
Looking from the code perspective, they’re variables used inside conditional statements that allow developers to use different sections of their code.
Implemented in the right way, feature flags are easy to control and can be used by Product Management, Sales, or Marketing teams. You will see an example in one of the following sections.
Feature flags have been a part of software development for a long time, but only in recent years has their popularity significantly increased. Let’s look at the areas where feature flags could be especially useful:
Currently, we have two separate Ruby on Rails applications, and we wanted to have one solution for both of them.
As you can see it’s enough to provide three parameters. The first one is a feature flag name that we’re going to use.
The second one is a user object. Feature flags can be enabled globally for everyone, but sometimes we want to be more precise and enable it for a specific user based on different parameters like an email or a public ID.
The last parameter is a default value. It‘s possible to use an external service that will control the value of a feature flag, and there’s always a chance that an external service will have unexpected downtime. That’s why it’s good to have a safe default value.
Let’s check an example below:
It’s a simple method where we can give a certain organization an option to execute an advanced type of test. As an example, the feature flag can be controlled by a product manager discussing different solutions with our customers.
The module provides our variation method and an additional method responsible for configuration that can be done from any application on which we’ve installed the gem.
The most important parts in the config are the provider and the UserDetailsFactory:
We’ve decided to use one of the paid solutions as our main provider (more about it below), but we left the possibility of connecting with any provider we want, as long as there’s a consistent interface implementing the variation method and the connect method that will depend strongly on the provider’s API.
UserDetailsFactory is another interesting class. It gives us the ability to show certain features only to chosen organizations based on their public ID or to target specific testers based on their email address.
It’s also super simple to extend the type of users we’re working with and add classes like OrganizationUser or even a Hash class where params don’t have to be related to the existing model.
The code visible above needs to have a provider of a variation value. As is often the case in the software development world, there’s an option to implement something in-house, use an open-source solution, or pay for a product that’s ready to use. We had to make this decision a few years ago, in 2018.
We checked a few paid solutions like Optimizely, LaunchDarkly, Google Optimize, and Roll-out. Besides that, we pondered a lot of questions in the area of build vs buy considerations and we finally chose LaunchDarkly as our feature flags provider. It includes both Ruby and Javascript SDK and it has a lot of well-documented features.
Quite recently, Dynatrace announced that with a consortium of top feature flag management solutions they’ve submitted a new open standard for feature flagging to the Cloud Native Computing Foundation (CNCF).
Dynatrace wants to create a language-agnostic and vendor-neutral standard for feature flagging and they’re planning a release for Fall 2022. The idea is to define a standard API and provide specification-compliant SDKs in various languages, such as Java, Node, .NET, and many others.
It’s a really interesting project that could simplify the way we work with feature flags and it’s worth watching it closely.
Below, you can see the interface created by LaunchDarkly. It shows the flag presented in one of our examples. The targeting is on and we’re returning true only for one organization with a specific public ID.
We’ve already discussed the positive side of feature flags, but let’s be honest, there must be some downsides, and we can’t simply skip them. Feature flags add more complexity to the software development process. Let’s check where things are affected the most:
Knight Capital Group (an American global financial services firm) learned this in the worst possible way. They lost $440 million in just 45 minutes and as a consequence, they were acquired by their rival a few months later.
If you would like to know more about what happened, there is an interesting case study available here.
What are some best practices for using feature flags?
Overall, our experience with feature flags has been really positive. We have been able to develop new features faster. We’ve been experimenting with different application settings and we’ve made decisions based on the real numbers, not just our hunches.
The key is to keep the number of feature flags under control and remove them as soon as they’re no longer needed.