The Art of Feature Flagging

Rate this content

Fed up with merge conflicts and system failures after a big release? Feature flags can be your lifesaver!

We strive to get new features to the hands of our users as fast as we sustainably can. Some features can take longer to develop and touch other parts of the system. If not handled with care, these kinds of features can result in merge conflicts that keep developers up all night, not to mention the dreaded system failures following a big release. Equipped with feature flags, we can avoid this nightmare and continuously deploy code changes safely.

This talk consists of practical tips on how to use feature flags as release toggles.

8 min
01 Jul, 2021

AI Generated Video Summary

Feature flagging is an effective practice in software development to prevent unexpected impacts of code changes. Virtuflex offers a solution for continuous integration and deployment, allowing developers to serve random comics with different randomizer options. Feature flags are used to control the behavior of AI systems during development, enabling gradual deployment and automated testing. Once a feature is complete and tested, the code and flag can be safely removed.

1. Introduction to Feature Flagging

Short description:

Hi, my name is Diani Yedono, and I've been developing software for over a decade. I would like to share one effective practice called feature flagging that I've been using to keep integrating and deploying my code. Sometimes changes to a code wouldn't affect any other part of the software system. However, even a little change can unexpectedly affect other parts. There are many processes that people use to ensure the software is protected from migrations introduced by any code change. One of the processes is to have long-lived feature branches.

Hi, my name is Diani Yedono, and I've been developing software for over a decade. I would like to share one effective practice called feature flagging that I've been using to keep integrating and deploying my code.

Let's start with thinking back in time. Can you remember that time when a system failure happened right after a big release? If you've never experienced that, I wish you don't ever have to because it's just awful. This comment shows a person asking another person to imagine they deployed a new version of their customer management system and 15 minutes later the online shop crashes.

Sometimes changes to a code wouldn't affect any other part of the software system. However, in many cases, even a little change can unexpectedly affect other parts. And that's quite normal. There are many processes that people use to ensure the software is protected from migrations introduced by any code change. One of the processes is to have long-lived feature branches. Each of the branches is extensively reviewed and tested before being merged. However, this can lead to another type of problem. This comment shows a developer who's trying to merge their branch into main. First, they pull the changes from main into their branch. Once they're happy, they're getting ready to merge their branch back into main. However, another developer has just merged a big chunk of change into main. Merging big changes can lead to merge conflict and that can keep developers up at night. And it's not a sustainable practice.

2. Introduction to Virtuflex

Short description:

Continuous integration is a popular practice in software development, but merging half-baked code can be challenging. Thankfully, Virtuflex offers a solution. This talk focuses on using Virtuflex for continuous integration and deployment. Let's explore an example web application that utilizes Virtuflex to serve random comics to users, with the ability to switch between a math randomizer and an AI-based randomizer.

These pains have led people to start practicing continuous integration, where developers continuously integrate their code changes into main, little by little and regularly. But what if the new feature takes rather long to develop? How can we merge half-baked code without affecting the users or consumers of the software?

Thankfully, Virtuflex can help us. Virtuflex has been used for many purposes, some of which are not part of this talk. So this talk is not about using Virtuflex for canary release, A-B testing, or Kailh switch. But this talk is about using Virtuflex for continuous integration, which is to continuously merge code changes into main or trunk, and continuous deployment, which is to continuously deploy code changes to production safely.

Now let's take a look at an example web application that is going to use Virtuflex. This is a web app that stores a collection of digital comics. It has one feature, which is to serve a random comic to the user. Initially, the website uses a math randomizer. Then it is decided to have a new feature and use an AI to serve a random comic to users. And this AI can serve the random comic depending on the weather, for example, or depending on what's trending in the world. I'm just making up some new features here. The randomizer needs to be changed to use AI. And it can take a while to do that.

3. Using Feature Flags for AI System Development

Short description:

While under development, we use feature flags to control the behavior of the AI system. By introducing a feature flag called 'AI randomizer,' we can switch between using the math randomizer or the AI randomizer based on the environment. The flag is stored as an environment variable, allowing us to safely build and deploy the AI randomizer code little by little. Automated testing is also implemented by creating tests for both flag states. Once the feature is complete and tested on the production environment, we can remove the code and the flag.

While under upward development, we want to show the progress of the AI system. For example, on a development or a UAT or QA environment. However, we don't want to release this half-baked feature to production yet. So we need a way to use either the math randomizer, or the AI randomizer, depending on the environment.

This is the initial code that uses a math randomizer to serve a random comic. Now, let's see how feature flag can make the web app serve a comic from either the math randomizer or from AI randomizer. On line six, we check a feature flag called feature flag AI randomizer. When it's on, we use AI randomizer to serve the comic. When it's off, we use a math randomizer instead. The feature flag is stored as an environment variable. On development environment, the value is set to be on, while in production, the value is set to be off. This way we can safely build and deploy AI randomizer code little by little and regularly to both dev and production. It can be continuously tested on dev and not affecting any production users. Once the AI randomizer feature is complete, we can turn the flag on on prod. That is when we release the feature. However, the code itself has been laying dormant on prod for a little while. So that's one way to do feature flagging. This example is for backend feature flagging. One nice thing about this technique is that it's very versatile and it can be used in other parts of the software. For example, on a web app front-end code or mobile app front-end code.

Right, so how about automated testing? How are we going to test features with flags? Let's check the test for this code. This is the initial test when the web app is only using the math randomizer. When the random API is called, it should return a fake comic, which is the only comic stored in the test data storage. When the flag is introduced, we explicitly set the flag to be off for the existing test. Then we add a test for when the flag is on. This way we have automated tests for both when the flag is on and off. For this particular example, the test is similar. They return the fake comic either when the flag is on or off. It's because we only have one fake comic in our test data storage. In many cases, a new feature has a different behavior and therefore different tests for when the flag is on and off.

So, we just went through the secret art of feature flagging. To sum up, we start by introducing the flag, we test for both when the flag is on and when the flag is off, and then we write the implementation code for when the flag is on and when the flag is off. We make sure that the flag is on onDEV and off onPROD. And then we deploy the code to DEV and we deploy the code to production as well, and it's going to be dormant on production because the flag is off. Once the release, once the feature is complete and we want to release it, we turn the flag on onPROD. And once we are happy that the feature has been behaving in an expected way onPROD for a little while, we can then remove the implementation code for when the flag is off, remove the test for when the flag is off. And then once we're sure that the flag is not used anywhere, we remove the flag. So this is the secret art of feature flagging.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

React Advanced Conference 2021React Advanced Conference 2021
19 min
Automating All the Code & Testing Things with GitHub Actions
Code tasks like linting and testing are critical pieces of a developer’s workflow that help keep us sane like preventing syntax or style issues and hardening our core business logic. We’ll talk about how we can use GitHub Actions to automate these tasks and help keep our projects running smoothly.
DevOps.js Conf 2022DevOps.js Conf 2022
33 min
Fine-tuning DevOps for People over Perfection
Demand for DevOps has increased in recent years as more organizations adopt cloud native technologies. Complexity has also increased and a "zero to hero" mentality leaves many people chasing perfection and FOMO. This session focusses instead on why maybe we shouldn't adopt a technology practice and how sometimes teams can achieve the same results prioritizing people over ops automation & controls. Let's look at amounts of and fine-tuning everything as code, pull requests, DevSecOps, Monitoring and more to prioritize developer well-being over optimization perfection. It can be a valid decision to deploy less and sleep better. And finally we'll examine how manual practice and discipline can be the key to superb products and experiences.
DevOps.js Conf 2022DevOps.js Conf 2022
27 min
Why is CI so Damn Slow?
We've all asked ourselves this while waiting an eternity for our CI job to finish. Slow CI not only wrecks developer productivity breaking our focus, it costs money in cloud computing fees, and wastes enormous amounts of electricity. Let’s take a dive into why this is the case and how we can solve it with better, faster tools.
DevOps.js Conf 2022DevOps.js Conf 2022
31 min
The Zen of Yarn
In the past years Yarn took a spot as one of the most common tools used to develop JavaScript projects, in no small part thanks to an opinionated set of guiding principles. But what are they? How do they apply to Yarn in practice? And just as important: how do they benefit you and your projects?
In this talk we won't dive into benchmarks or feature sets: instead, you'll learn how we approach Yarn’s development, how we explore new paths, how we keep our codebase healthy, and generally why we think Yarn will remain firmly set in our ecosystem for the years to come.
DevOps.js Conf 2024DevOps.js Conf 2024
25 min
Atomic Deployment for JS Hipsters
Deploying an app is all but an easy process. You will encounter a lot of glitches and pain points to solve to have it working properly. The worst is: that now that you can deploy your app in production, how can't you also deploy all branches in the project to get access to live previews? And be able to do a fast-revert on-demand?Fortunately, the classic DevOps toolkit has all you need to achieve it without compromising your mental health. By expertly mixing Git, Unix tools, and API calls, and orchestrating all of them with JavaScript, you'll master the secret of safe atomic deployments.No more need to rely on commercial services: become the perfect tool master and netlifize your app right at home!

Workshops on related topic

DevOps.js Conf 2022DevOps.js Conf 2022
152 min
MERN Stack Application Deployment in Kubernetes
Deploying and managing JavaScript applications in Kubernetes can get tricky. Especially when a database also has to be part of the deployment. MongoDB Atlas has made developers' lives much easier, however, how do you take a SaaS product and integrate it with your existing Kubernetes cluster? This is where the MongoDB Atlas Operator comes into play. In this workshop, the attendees will learn about how to create a MERN (MongoDB, Express, React, Node.js) application locally, and how to deploy everything into a Kubernetes cluster with the Atlas Operator.
DevOps.js Conf 2022DevOps.js Conf 2022
13 min
Azure Static Web Apps (SWA) with Azure DevOps
Azure Static Web Apps were launched earlier in 2021, and out of the box, they could integrate your existing repository and deploy your Static Web App from Azure DevOps. This workshop demonstrates how to publish an Azure Static Web App with Azure DevOps.
React Summit 2023React Summit 2023
88 min
Deploying React Native Apps in the Cloud
Deploying React Native apps manually on a local machine can be complex. The differences between Android and iOS require developers to use specific tools and processes for each platform, including hardware requirements for iOS. Manual deployments also make it difficult to manage signing credentials, environment configurations, track releases, and to collaborate as a team.
Appflow is the cloud mobile DevOps platform built by Ionic. Using a service like Appflow to build React Native apps not only provides access to powerful computing resources, it can simplify the deployment process by providing a centralized environment for managing and distributing your app to multiple platforms. This can save time and resources, enable collaboration, as well as improve the overall reliability and scalability of an app.
In this workshop, you’ll deploy a React Native application for delivery to Android and iOS test devices using Appflow. You’ll also learn the steps for publishing to Google Play and Apple App Stores. No previous experience with deploying native applications is required, and you’ll come away with a deeper understanding of the mobile deployment process and best practices for how to use a cloud mobile DevOps platform to ship quickly at scale.
DevOps.js Conf 2022DevOps.js Conf 2022
163 min
How to develop, build, and deploy Node.js microservices with Pulumi and Azure DevOps
The workshop gives a practical perspective of key principles needed to develop, build, and maintain a set of microservices in the Node.js stack. It covers specifics of creating isolated TypeScript services using the monorepo approach with lerna and yarn workspaces. The workshop includes an overview and a live exercise to create cloud environment with Pulumi framework and Azure services. The sessions fits the best developers who want to learn and practice build and deploy techniques using Azure stack and Pulumi for Node.js.