Crazy as it sounds: manage your feature flags with a cat
Tags: featureflag, featuretoggle, configcat, tutorial
Published: 2021-03-17 21:36:14

My one-year-old has recently started walking. He falls down a million times a day, sometimes he even hurts himself, but as soon as he gets up he keeps on going. Why? Because he feels safe and encouraged. Failure – or the risk of it - is part of the process but if you have the right support you don’t need to worry. 

Well, dear Product Owners, I've got some good news for you. When it comes to feature releases [ConfigCat](https://configcat.com) - a cross-platform feature flag service - gives you the safety net you need.

#Launch, test, or fix a feature without making it instantly visible to all users 

Let’s say your latest feature is ready for deployment. You are all excited and certainly want a seamless induction for your users. Now, that’s when ConfigCat comes into play. It allows Product Owners to turn a feature on and off without actually deploying code. So you can gradually introduce and test any new development on a specific group of users, even roll it back if needed.  
Let’s see how ConfigCat works and what’s in it for you in the following sections. 

#How to deploy features gradually with feature flags
Working with feature flags gives you the freedom to decouple feature releases from code deployments. This means that you can manage and control the development process step by step. 

Here is an example:
I like to try out new recipes but I always need to watch those damn macros. (Hands up mates! ☺). I usually track what I eat in the MyMacroCounter (fictive) app so I can keep an eye on the consumed calories throughout the day. If I add a new item manually to the tracking list or scan a barcode from a food package the app will count its macros for me.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6dj453bip2eo8yqya7em.jpg)

Let’s say a new recipe integration feature has been developed for this app. From now on users can link recipes directly from a website and the system automatically adds the list of ingredients to the macro calculator. It saves them a lot of time as they don’t need to enter each ingredient manually. Hmm...I already love the idea! 

After the recipe integration feature is implemented you want to make sure everything works fine before deployment. You might take a baby step first and test the new function with just a small group of users. If everything is OK (or you have implemented the constructive feedback) you can expand the scope and keep on testing with a wider audience. Or you might set apart a special group of  “sensitive users'' who need to be approached with additional care and thought. They can be involved at the very end of the release process with almost 0 risk of bad user experience.

ConfigCat can support all the options above for a gradual feature release.

#A gradual roll-out step by step guide
Let’s get back to our example and see how to control feature flags with ConfigCat. 

* Open the dashboard and click add feature flag
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6e3ujhdnuc9q1810o2dv.png)
* Enter a name and key for your new feature flag. It is a good idea to give it the same name as the feature you are implementing.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/skydfr8dlh0ot4ra9om7.png)
 If you scroll down on the Feature Flags and Settings page or swap to the SDK Key tab, you will see a simplified guide on how to connect your application to ConfigCat. There is a different one for all the technologies that ConfigCat supports.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g7lpqj7bw8en1iiyn8pj.png)


* You can launch the feature for your first group of testers (employees of the MyMacroCounter brand) by adding a new targeting rule. Set the targeting rule so if a user’s email address *CONTAINS* `@MyMacroCounter.com`, then the recipe integration feature is turned on. In all other cases, the feature is turned off.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sxuwo40cn2ey08rsacnn.png)


##How to roll-back using feature flags
* Now let’s suppose you receive feedback that the function doesn’t work properly for recipes written in  Spanish. Normally, when users add a link to a recipe (list of ingredients + instructions on how to prepare the meal) the app separates the 2 main parts and only adds the list of ingredients to the macro calculator. But it seems like the system has trouble recognising the non-English-based text and for recipes written in Spanish merges the description of the method with the list of ingredients. Without a clear list the MyMacroCounter can’t read the data. 

This seems like a language barrier that needs to be fixed.

No worries, just turn the feature off for everyone until the Developers fix the bug and you run the test again. Users will still be able to use the app without the new feature and won’t have a bad experience with MyMacroCounter. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kuw2ix5s2xb7w5sxhy01.png)

##Expanding the scope of users
* If in the 2nd round the induction is seamless with your first test group you can deploy the function to further groups like friendly users, those based in Spain etc. So you can check if the recipe integration works well with a wider group of users and get their feedback too.(And btw they will never know you have already fixed a bug.) You can keep your sensitive users (for example premium users who pay for the app or those who tend to complain) for the final release to protect them from the bad user experience.   
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5gn56n1dba7fbcmjxs2k.png)

Alternatively or on top of the previously targeted groups, you can set (and increase) a certain percentage of all users to whom you roll out the new feature and in the end turn it on for everyone by adding a percentage option to the feature flag.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p0je1plnunppdn5l74o6.png)

And just remember, in case of a problem you can turn the feature off anytime.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/axlcszsfcqco7yhza5hz.png)
After successful roll-out, you can remove the feature flag related code (that you have inserted in the 1st step)  as it is no longer necessary. 

Now that sounds neat, doesn’t it? You can target user groups by email address, location, subscription or any other custom user attribute. ConfigCat supports % rollouts, A/B testing or variations so you can really choose the option that fits your needs.

#Key takeaways
**Releasing features with feature flags has its advantages, like the ability to test on live users without the risk of losing brand reputation. Decoupling feature releases from code deployments reduces stress and dependencies within the organization. Trying out even crazy new ideas in production supports innovation. Marketing teams can go live whenever they want with minimal support from the development teams. And in the rare case when something hits the fan, an emergency kill-switch button closes by emerges confidence.**

#Here are a few links if you want to dig deeper
- [Feature Toggles (aka Feature Flags)](https://martinfowler.com/articles/feature-toggles.html)
- [Getting started with ConfigCat](https://configcat.com/docs/getting-started)
- [An In-depth Look into User Targeting] (https://configcat.com/blog/2020/11/19/user-targeting)
- [Targeting specific users - a step by step guide](https://configcat.com/docs/advanced/targeting)
- [Trunk-Based Development - an overview](https://medium.com/@mattia.battiston/why-i-love-trunk-based-development-641fcf0b94a0)