DEV Community

Cover image for How to use feature flags for staged rollouts
Pradumna Saraf
Pradumna Saraf

Posted on

How to use feature flags for staged rollouts

In the software development world, we use a rollout strategy to update the existing version of an application or software, initially to limited devices or users and then to other devices once it is confirmed that the software update is safe for all devices, following feedback and testing. This helps control the way we release features and versions to users.

One of the most popular strategies many companies use is the staged rollout (or phased rollout). A prime example can be seen with Instagram: your friend may have some extra features on their Instagram, but you don’t. After some time, you may receive those features, or they might be removed because the company didn't find them to be a good fit or discovered bugs, etc., prompting a rollback.

What is a Staged Rollout?

Staged rollouts let developers release a version gradually and make it slowly available to a larger audience, for example, adding dark mode functionality to our app and making it available for a small percentage, like 5% of our user base. The benefit of doing this is to limit the scope of any bugs or issues that might occur in the release. Additionally, this helps to gather initial feedback. One of the most important reasons is that if a feature gains significant interest and shows a trend, it might require a lot of effort to build, and the company needs to ensure results to justify the investment of money, time, and effort.

How do Feature Flags Work With Staged Rollouts?

The Staged Rollout strategy has traditionally been restricted to DevOps professionals. It is complex and involves a lot of back and forth between development and DevOps teams. Developers were never directly involved in this process. However, with Feature Flags, developers now have more power and control over the end product.

With feature management platforms like Flagsmith, we can easily create and manage flags directly from the UI. Staged rollout features are built into the UI, but we can also use the tool for A/B testing, basic feature toggling, and more. In the example below, we will see a demo of creating a simple dark mode feature and initiating a staged rollout to users.

How to Create a Staged Rollout

Head to Flagsmith and create a free account. You can do this in a couple of clicks by going to: https://app.flagsmith.com/signup. Once your account is created, click on the Features button on the right panel and then click on the "Create Your First Feature" button.

Flagsmith Dashboard

You will get options to create a new feature flag as you click through. For the demo, let’s create a flag for a dark theme. Give it an ID; it’s essential and helps us to identify and retrieve the value when we access this flag in our code. The control value can be anything like a font size or footer size.

In this specific use case, we will treat it as a percentage to control the percentage of users that can see the dark mode theme. Variations are pre-defined values; here we are setting how many people will have access to dark mode. We can add a tag and description for better information if we want, otherwise, we can leave it. After filling in all the necessary details, click on the "Create Feature" button.

When this is set up, only 10% of users can access dark mode.

Flagsmith Dashboard

After you click on "Create Feature," you will see your flag listed, and it will be turned on. Now, to test it, click on the "Run Test" button to ensure the flag is working properly.

Flagsmith Dashboard

You will see the results indicating that the flag is enabled and has a value of 90. If you're wondering why variant weightings are not viewable, we need to pass in an Identity while using the SDKs.

Flagsmith Dashboard

Let's say the initial rollout went well and there was no buggy code/negative feedback. In that case, we can roll out to more users! Let’s change the values from 90 to 80% and increase the dark theme's visibility from 10% to 20% of users.

Now, 20% of the total users will be able to see the dark theme feature. Also, we can schedule the updates if we want (this is another great feature of Flagsmith’s).

Flagsmith Dashboard

Click the test button to verify. It's now changed to 80%.

Image description

Now that everything is working and flags are set, we can use SDKs to access the flag value and state. Flagsmith supports a wide range of SDKs.

Once it's live, we can analyse its performance and make adjustments to percentage values without the need for redeployment. We can gradually increase the percentage if the results are positive and slowly make the rollout available to all users.

Use Cases for Staged Rollouts with Feature Flags

Here are some of the most useful use cases where developers can benefit from staged rollouts with feature flags:

  • Streamlining the DevOps to developer handoff.
  • Getting feedback on new features.
  • User testing and beta testing.
  • Risk mitigation and compliance.
  • Compatibility testing to ensure it works on different devices and systems.

Conclusion

To sum it up, with feature flags, developers have the power to use different strategies to release their updates and tests, making the whole process smoother and more manageable. It's a handy tool for developers to improve their work!

There are also open source options! Check out the repo here and don't forget to give it a star to show your support and join their amazing community to get technical support.

Top comments (2)

Collapse
 
jitendrachoudhary profile image
Jitendra Choudhary

Helpful post pradumna

Collapse
 
pradumnasaraf profile image
Pradumna Saraf

Thank you, @jitendrachoudhary