Testing in Production with Feature Flags

 2 years ago
source link: https://scotch.io/tutorials/testing-in-production-with-feature-flags
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

In November of this year, Instagram introduced a new feature to remove likes from your Feed. They chose to roll out this feature gradually and test in production to fully understand the impact of their decision. How do users react? Does it impact the way they use the application? Does it impact their satisfaction? Does it cause abandonment? How does Instagram achieve the magic of testing in production and how can you follow suit.

Table of Contents

  • What are Feature Flags?
  • Why are Feature Flags Needed?
  • How are Feature Flags Implemented?
  • Feature Flag Management
  • How Can Feature Flag Management be Implemented?

How do you manage feature flags? How do you do testing in production with multiple features being toggled? How do you automatically aggregate this data? How will gradual releases be handled? How do you segment users to and decide who receives the feature? In this post, you will learn how to implement feature flags to answer these questions.

What are Feature Flags?

Features flags are simply a technique in which toggles are used to conditionally release features to end-users of a product. At its base, feature flags are programmatic conditional toggles which return some logic based on the truthy or falsy value of a condition. While teams are constantly shipping features taking into account the inherent test-driven development methodologies, stress or smoke test, nothing beats testing with real-life data as efficiently as possible.

Using feature flags as a mechanism for testing is a way to capture accurate data and feedback into the development cycle to ensure an efficient product iteration process.

In essence, feature flags are used to turn off or turn on certain application logic based on set variables. These can be used for either simple product feature tests in production, or enterprise application launched to millions of users.

Why are Feature Flags Needed?

It is important to validate a feature once it is released. What better way to validate a feature than to put it to work against real traffic and get real data. If something goes wrong, a change is pushed to the variable in the condition to turn off the feature. If things go well, you can strategically release the feature to a broader audience.

There will always be a need to test features in QA in a testing or staging environment. But there will always be builds that fail in production. Testing in production helps us understand where things are failing before large swaths of users are impacted.

How are Feature Flags Implemented?

As previously stated, the base use of feature flags in development is simply a conditional toggle with which certain logic or elements in a program can be enabled or disabled. Looking at a simple JavaScript program, a feature flag might be:

Essential Reading : Learn React from Scratch! (2019 Edition)
let featureControl = true;

if (featureControl) {
    // Complete this logic in the code block if the value of featureControl is truthy

} else {
    // Complete this other feature in the code block if the value of featureControl is falsy


This simply runs the logic in each block depending on the condition of featureControl .

This data can be stored in an app-wide config file, or read from a database. Better still, it can be stored in an environment variable, hence a change to this environment variable will enable or disable the feature.

Feature flags can be implemented on the client or server-side to toggle either the user interface or some server logic. Using conditional statements to manage a feature is a basic use case. However, several techniques applying conditions and a bit of performance engineering for more sophisticated feature flagging strategies.

Feature Flag Management

While managing single feature flags and implementations can be straightforward, handling large amounts of feature toggles can be a pain. This is where feature flag management comes in. Manually managing multiple flags within your codebase can be a daunting task.

A good feature flag management solution will help users manage their flags from a central interface with proper analytics and robust control.

Feature flag management provides the means to properly handle:

  • Analytics
  • Phase releases and migrations
  • A/B and Smoke Tests with live data
  • Grouping and testing in segments
  • Feature audit logs, deployment events and much more

Amongst others, feature flag management provides the following benefits:

  1. Allows more focus on the business requirements of the product
  2. Reduced risk factor as features can always be turned on/off in real-time depending on received data
  3. Increased development speed
  4. Feature releases that are decoupled from deployments which means less effort will be spent handling the deployment infrastructure on a feature release level
  5. For product teams, this ensures the rapid validation and iteration on features and entities in an organizations roadmap
  6. The ability to target select groups of users based on varying qualities and rollout features to that segment

How Can Feature Flag Management be Implemented?

CloudBees Rollout is an enterprise-ready feature flag management solution with robust deployment rules, audience segmentation, and a testing framework for controlling which audiences are exposed to what features. With CloudBees Rollout you can roll out and roll back features, test and target features for specific customer segments for fast feedback, and use gradual rollout and rollback capabilities to sidestep the danger of 'big bang or bust deployments'.

High-level features include:

  • Powerful Feature Flag Management
  • In-depth analytics on feature deployments and events
  • Deep segmentation and custom rules to better target a select audience to test a product
  • A wide range of SDKs and platform integrations
  • Multiple environment feature flag management
  • Mobile feature flags

CloudBees Rollout lets you utilize all the features of a standard feature management tool and even more. With Rollout, the decoupled nature of the feature releases and product deployment ensures that engineering and product teams are more focused on building solutions to user verified problems in real-time. This is with user feedback, rather than spending time figuring out what's best for users, in development.

CloudBees Rollout is super easy to setup. A 3 step integration with a sample React-Native application requires you to:

  • Signup for CloudBees Rollout for free
  • Create a new application while selecting the application type and environment
  • Integrate CloudBees Rollout with the React-Native app with an npm package


This automatically connects your app with the CloudBees Rollout dashboard and you can get to creating feature toggles. To learn more, visit the documentation .

Feature flag management is essential for modern product teams. Get started with Rollout for free today .

Like this article? Follow @iChuloo on Twitter

This content is sponsored via Syndicate Ads .

About Joyk

Aggregate valuable and interesting links.
Joyk means Joy of geeK