Instantly releasing features in a world that never sleeps, using Feature Flags
Tags: xamarinforms, xamarin, featureflags, softwaredevelopment
Published: 2019-11-05 14:11:20

---
title: Instantly releasing features in a world that never sleeps, using Feature Flags
published: true
date: 2019-02-14 14:24:09 UTC
tags: xamarin-forms,xamarin,feature-flags,software-development
canonical_url: 
---

![Related image](https://cdn-images-1.medium.com/proxy/1*HROSl2j8Ib7keDGF6_8PTQ.jpeg)

Now more than ever, businesses need to be nimble and continue to ship features at the speed of light™. This is even more true in the very competitive world of mobile apps.

Long gone are the days where we could wait several months to release a new version of our app.

These days, customers expect from your mobile app the same nimbleness as their Facebook app, Banking app or Dating app. And if you are not willing to do it, the competition will.

As you might know (hopefully thru the pain of others), it is very risky to roll out a faulty feature, as, in the world of the App Store, a new release could take between [1 and 2 days to be approved](https://developer.apple.com/app-store/review/), and this could make your customer’s confidence in your product be lost forever.

So, how can we serve both masters? the ever insatiable desirer of new features, while still serving the Lord of Always-Works-Never-Roll-Back?

[Feature Flags](https://martinfowler.com/articles/feature-toggles.html), my friend! They are the stuff dreams are made out of.

> “With Feature Flags, you can launch brand new features and experiences in real-time. You don’t have to go all in with every feature in every release, which removes a lot of risk and enables you to instantly roll back if the feature needs more work.”

> – Nancy Hua, CEO, Apptimize.

So now, let’s talk about how to do Feature Flag as a Service, by utilizing [LaunchDarkly](https://launchdarkly.com/) to make instant releases of features within our Xamarin Mobile app.

Let’s say, our Mobile Banking App team is rolling out a very innovative feature, called **Spending Analysis**. This feature tracks expenses and income over time and tells the customer how much money they have leftover to spend. Now, our Data Science Department is still tweaking the algorithm, so they want to make sure that the feature can be rolled out to just a subset of their customers, and eventually to the entire consumer base.

![](https://cdn-images-1.medium.com/max/1024/1*MWFRlEe13Ih56FJt0faq8A.png)<figcaption>This is what the final result should look like once we turn on the feature.</figcaption>

The LaunchDarkly website has a very simple sign up process and [onboarding](https://app.launchdarkly.com/signup). It took us about 20 seconds to do so, and we were in. The site gives you the choice of doing a Quickstart, or to skip straight the dashboard; We chose the later.

Creating a feature flag for our mobile app was simple. We gave it a name and key. We also selected a **Boolean** as the kind of flag. Lastly, we checked the box says _Make this flag available to client-side SDKs,_ in order for the flag to be provided to our mobile app later on.

![](https://cdn-images-1.medium.com/max/1024/1*HxBJ6DNcBD7jwiPxC7tzgQ.png)

After having created a few feature flags, we are almost in business.

![](https://cdn-images-1.medium.com/max/1024/1*qCaQAlhw2xcsQY2ukeM6-A.png)<figcaption>LaunchDarkly Dashboard</figcaption>

We then moved over to the client side of the story and implemented the Spending Analysis, and placed on the Main Page of the Mobile App.

![](https://cdn-images-1.medium.com/max/752/1*xYLJ_Z6bWQci4bb4iKwCug.png)<figcaption>Spending Analysis Widget</figcaption>

Let’s add LaunchDarkly Xamarin SDK to our project, by including the [LaunchDarkly.Xamarin](https://github.com/launchdarkly/xamarin-client) NuGet package to your .NET Standard project. **_At the time of writing_** , the NuGet package is still in **pre-release** , version 1.0.0-beta9. There is also a more mature .NET client, but since we like to live on the edge, let’s stick to the Beta.

![](https://cdn-images-1.medium.com/max/1024/1*SFBTevUgZ9xoH7ep5nRF9g.png)

```
Install-Package LaunchDarkly.Xamarin
```

At some convenient time, during your app initialization sequence, you would want to initialize the LaunchDarkly client.

By now, you should be familiar with the paradigm these mobile SDKs have. You create a project, that gives us some sort of _key_, to be used as a form of authentication. We have stored this in a field called MOBILE\_KEY\_TEST.

{% gist https://gist.github.com/claudiosanchez/23f6151f1079e07865619332c7b02470 %}

After you have initialized the LaunchDarkly client, it will by default, communicate with the LaunchDarkly cloud and **download** all of the feature flag information. This includes a list of the feature flags and their state.

Each feature flag has a unique **name/key.** Our new feature will be using the key **_can-see-spending-analysis._** I have placed my keys in a convenient static class for ease of access.

{% gist https://gist.github.com/claudiosanchez/cb92791aeb145a0474c94ac7fa032304 %}

Checking if a feature flag is on or off, is pretty straightforward. From our _MainPage_ ViewModel, we are calling a Service we implemented to abide by the [Separation of Concerns and Single Responsibility principles](https://deviq.com/separation-of-concerns/).

The ViewModel calls the _Can()_ method of the _FeatureFlagService_, to check on whether or not it should display the _Spending Analysis_ widget.

{% gist https://gist.github.com/claudiosanchez/d82f5b0440c2eaf0e0c3d97d7373653b %}

At this point, the Spending Analysis widget is present in our app. We deploy the new version of it, and we notice that the _Spending Analysis_ feature does not appear! — Do not despair, that should come as no surprise, as we **have not turned on the feature flag ON yet.**

![](https://cdn-images-1.medium.com/max/1024/1*PptvsLDDVSKR4TJePq43qA.png)<figcaption>The new feature is present in the code but is disabled via Feature Flags.</figcaption>

At this point, the person in charge of turning on features for our App can simply access the LaunchDarkly Dashboard and turn the feature ON.

![](https://cdn-images-1.medium.com/max/1024/1*8fKvMQvNWkvefEVFA4ArDA.png)

A Voila! The feature is ON!!

![](https://cdn-images-1.medium.com/max/1024/1*TMULv2UnxtTt05Rhw0qi6A.png)

* * *