Using ConfigCat for Staged Rollouts and Canary Releases
Tags: stagedrollouts, canaryrelease, featuremanagement, featureflags
Published: 2024-01-18 15:07:11

The primary goal of software developers is to ensure user satisfaction with the features or updates they introduce. However, achieving this goal can be challenging without the right release strategy. The question often asked, then, is, "How can developers be certain that a new update or feature delivers optimal results to end users?"

Two strategies that can be employed to address this concern are staged rollouts and canary releases. These strategies can be implemented using feature flags, and in this article, we explore how [ConfigCat](https://configcat.com/), a popular feature flag provider, can be used to perform staged rollouts and canary releases.

![Using ConfigCat for Staged Rollouts and Canary Releases cover](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/393u60rucsx7xu78tu73.png)

<!--truncate-->

## What are staged rollouts and canary releases

Staged rollouts and canary releases are both techniques used in software deployment, but they differ in their approach and purpose:

- Staged Rollouts: In a staged rollout, the new feature or software update is gradually released to a larger percentage of users over time. It typically starts with a small group and increases in stages until all users have access to the update. This method is used to monitor its performance with users and gather iterative feedback while minimizing the impact of any potential bug or issues.

- Canary Releases: Canary releases on the other hand involve deploying the new version or feature to a small subset of users initially, often chosen at random or based on specific criteria, before pushing them out to the entire user base. This group, referred to as the 'canary', acts as a test to gauge the new version's stability and performance. If no issues arise, the release is then rolled out to the entire user base. This approach is more focused on identifying and addressing issues before they affect all users.

In essence, while both strategies aim to mitigate risk by releasing software updates to a subset of users initially, staged rollouts do so in a more gradual, phased manner, whereas canary releases target a smaller, more specific group for initial testing. This ensures that the new changes introduced work as expected while minimizing any negative impact on the user experience.

Here is a diagram that illustrates a staged rollout and a canary release:


![Diagram of staged rollout and canary release](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j374m0t4mf1b0xu18e80.png)

## The role of ConfigCat in staged rollouts and canary releases

[ConfigCat](https://configcat.com/) is a feature flag management service that serves as a [central dashboard](https://app.configcat.com) to easily manage your feature flags and provides the essential tools needed to perform a staged rollout or canary release.

But how can these strategies be implemented and used? The simple answer is to use feature flags.

The first step is to create a feature flag for the new feature. Then, wrap the feature's code in a conditional if-statement that checks if the feature flag is enabled. This would allow the feature to be included in the app's code base, but until its flag is toggled on, it will be hidden from users.

Instead of showing the new feature to everyone when the flag is on, you can configure the flag to allow the adoption of either strategy. This is where the magic of ConfigCat comes in, specifically its [user-targeting capabilities](https://configcat.com/docs/advanced/targeting/).

## Performing a canary release with ConfigCat

To perform a canary release using ConfigCat, one can leverage its user-targeting abilities. Once the feature flag is created, user-targeting rules can be configured to target users based on their email, country, or any other custom attribute.

For instance, if a new feature should be rolled out to only users within a company, you can set an email target rule. In the ConfigCat dashboard, the `CONTAINS` operator can be used to target all email addresses that contain `@yourcompany.com`. This will ensure that only users with email addresses containing `@yourcompany.com` will have access to the new feature. Here's how to do this:

1. Create a new feature flag in the [ConfigCat dashboard](https://app.configcat.com) with the following details:

- Name: `Chat feature`
- Key: `chatFeature`
- Description: `A new chat feature for our mobile app`

![Adding a feature flag in ConfigCat's dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wrmbsrwpwf1t5eleqy1g.png)

2. Click the *TARGET SPECIFIC USERS* button and select `Email` as the comparison attribute to target. Then, select the `CONTAINS` comparator from the dropdown and enter `@yourcompany.com` as the comparison value. Here is what that looks like in the ConfigCat dashboard:

![Setting a targeting rule on the figure feature flag](/assets/using-cc-for-staged-and-canary-releases/setting-a-targetting-rule.png)

Now that the feature flag and targeting rule have been created, the next step is to integrate ConfigCat's SDK client for the appropriate [coding language](https://configcat.com/docs/sdk-reference/overview).

3. The code snippet below shows how [ConfigCat's JavaScript SDK](https://configcat.com/docs/sdk-reference/js/) can be used to check if the chat feature is enabled for a user. Start by installing the SDK:

```bash
npm i configcat-js
```

```js
// Import the ConfigCat SDK
import * as configcat from "configcat-js";

// Initialize the SDK with your SDK key
const configCatClient = configcat.getClient("YOUR-CONFIGCAT-SDK-KEY");

// Define the user object
const user = {
  identifier: "f8c9c1a5-7d9c-4c7e-9e4c-9d3d2b5b3c5c",
  email: "jane@yourcompany.com",
};

// Get the value of the feature flag, while passing in the user object

const chatFeature = configCatClient.getValueAsync("chatFeature", false, user);

// Check if the chat feature is enabled
if (chatFeature) {
  // Show the chat feature
  loadChatFeature();
} else {
  // Hide the chat feature
  doSomethingElse();
}
```

Because the user Jane has an email address that contains `@yourcompany.com`, she will have access to the chat feature.

Scenarios can be different, and email is not the only way to target users. Users can also be targeted based on their country, or any other custom attribute. More information on how to do this can be found [here](https://configcat.com/docs/advanced/targeting/).

## Best practices for using ConfigCat for staged rollouts and canary releases

Rollouts and canary releases are great ways to test and evaluate new features and changes before making them live for the entire user base. To achieve the best results, a well-thought-out plan and design are required. Here are some general best practices to keep in mind when using ConfigCat for staged rollouts and canary releases:

- **Start small**: When performing a staged rollout or canary release, it's best to start with a small subset of users. This will allow the new changes to be tested on just a few users before rolling it out to everyone. In addition to the example described above, ConfigCat also provides a percentage option for setting the percentage of users that should have access to the new feature. Here is an example of what that setting looks like:

![Using a percentage option](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tyqu7xuv8bkarwdoklwg.png)

- **Roll out gradually**: Once the new changes are released to a small subset of users, continue rolling it out gradually if the feedback is satisfactory. This will allow the new changes to be evaluated by larger subsets of users before they become available to everyone. In the example provided, if the feedback is positive, you can add more targeting rules to the feature flag to make the chat feature available to more users.

- **Monitor and analyze**: This will help provide valuable insights to determine if the new feature or update is working as expected. Using commercial tools like [Amplitude](https://amplitude.com/) and [Datadog](https://www.datadoghq.com/) can aid in monitoring and analyzing the results of each rollout in real-time. Here are links to some blog articles that discuss this topic in more detail:

  - [Amplitude and ConfigCat: A Guide on User Segmentation with Custom User Attributes](https://configcat.com/blog/2020/12/10/custom-segmentation/)
  - [How to A/B test your React Native application using feature flags](https://configcat.com/blog/2023/02/14/how-to-implement-ab-testing-in-react-native/)
  - [Running an A/B Test in Android Kotlin Using ConfigCat and Amplitude](https://configcat.com/blog/2023/06/09/how-to-ab-test-kotlin/)

- **Have a recovery strategy**: Even though the new changes are tested on a small subset of users, there is still a chance that they may not work as expected when the feature reaches more users. Having a recovery strategy in place is essential. It allows you to roll back the changes if they do not work as expected. With ConfigCat, performing a feature rollback is just a few clicks away, and the best part is that you can do this from the [dashboard](https://app.configcat.com) without ever needing to edit or modify your application's code.

## Has ConfigCat proven itself in the real world?

The short answer is, yes! ConfigCat has been used by many companies to perform more than just staged rollouts and canary releases. Kantan.tech is one of those companies. In the blog article '[Kantan.tech Moves Faster than Their Competition](https://configcat.com/blog/2022/03/24/how-kantan-successfully-uses-configcat-in-its-ci-pipeline/)', they describe that before deploying to production, they would turn flags on for internal users using ConfigCat and run one last smoke test. Once satisfied, they'll enable the flags for all users. Many other companies are also using ConfigCat in similar ways; you can read more [here](https://configcat.com/customer-success-stories/).

## Conclusion

Staged rollouts and canary releases are effective strategies for testing new features and updates before rolling them out to all users. The benefit of both strategies is that they allow for testing in production on real users, which is the best way to get feedback on how a new feature or update is working. With the power of feature flags and the [targeting capabilities](https://configcat.com/docs/advanced/targeting/) of [ConfigCat](https://configcat.com), these strategies can be seamlessly integrated into any development workflow.

As we aim to improve software for end users, staged rollouts and canary releases will remain vital. The implementation of these strategies may often vary, but feature flags will undoubtedly remain a key component. In addition to what we've discussed, feature flags have many other applications, as they can also be used for A/B testing, dark launches, and more; the possibilities are endless. Furthermore, they are compatible with a variety of [programming languages and popular technologies](https://configcat.com/docs/sdk-reference/overview/) such as Azure, AWS, Zoho, and [more](https://configcat.com/docs/integrations/overview/).

Excited to give feature flags a try? You can get started with ConfigCat for free [here](https://app.configcat.com/auth/signup). Deploy any time, release when confident. I have been using their free-forever plan in all my side projects and it has been great.
You can also find more information on ConfigCat [here](https://configcat.com/#product).