Building Freetrade

How we use feature flagging in client apps

Alexander Broadbent

February 9, 2021

Alexander Broadbent

Software Engineer Alexander Broadbent shares what we do in the shadows, and why it helps us to carefully develop features.

Intro


We use feature flags to be able to quickly and safely develop features without disrupting other teams at Freetrade. 

While making changes on the Android and iOS apps we will enable features only for staff and our beta testers so we can get feedback in our live environment as we develop them.

We work in three verticals, which means we need to work on the same parts of the client apps and server at the same time, and we require extensive testing to ensure our new features are working as expected. Each team can be developing more than one feature in parallel so we require feature flags to split out different journeys through the app.

An example of usage was implementing the Open Banking flow into the client apps and testing the integration in production for over a month before releasing the feature to end users by enabling the feature flag for everyone. 

We needed to test different parts of the user experience through the client app which meant restricting the open banking flow to only test users and not breaking the existing top-up method for users in production. Being able to test the Open Banking flow in production was invaluable to solving all issues up front before releasing it to all users.

Our team at work



Core Concept


Put simply, a feature flag is a gate which checks a true or false value and controls whether to allow a user through a particular journey through the app. Let’s look at what a feature flag is and an example of how it can be used:

Let’s look at when a user logs in and they usually see an Account Overview screen. Our team is adding a new Account Homepage with even more information on it. We will add a new Feature Flag which, when enabled, will direct users to the new Account Homepage, rather than the current screen:


```kotlin

loginButtonClick

.withLatestFrom(flagService.isFeatureEnabled(“RedirectToHomepageOnLogin”))

.subscribe { (click, redirectToHomepageOnLogin) ->

when (redirectToHomepageOnLogin) {

true -> router.goTo(AccountHomepageScreen())

else -> router.goTo(AccountOverviewScreen())

}

}

.addTo(disposable)

```


We covered how we use reactive programming at Freetrade in another blog post, but essentially what is going on here is when the user clicks the Login button - we get the latest value of the feature flag for the user, and if it’s enabled they are directed to the Account Homepage screen otherwise they are directed to the old Account Overview screen. Remote configuration setup only allows feature flag changes infrequently, so we use Firestore to make flag changes instant, so changing the flag in the database sees the immediate effect in the client app.

We default all feature flags to `false` in production at the global-level, so when we are developing the feature we can push this code into production and it won’t have any impact on the users until the feature flag is enabled.

This is a really powerful way of being able to test our new screen as it lets a select few members of staff try out the feature against the real stock market before the feature is released to everyone.

There is a design choice and a compromise to make between blocking off whole or partial features from every user and allowing some users through.


Our Feature Flag Approach


What was interesting for me when I joined Freetrade is that the app contains a whole lot more than meets the eye.

All features that are in development are in the app that everyone gets from the App Store, but they just can’t see everything until the feature flags are enabled. Our feature flag approach follows the Release Toggles from Martin Fowler’s Feature Toggle blog post which is how we separate our feature releases from our code deployment by enabling features after they have been deployed into production. 

We made a choice to try and use the feature flag as an entry point into the feature we are adding. This means that we don’t have a lot of complicated conditional logic in our codebase and each individual user flow is deterministic in it’s behaviour. We can see this choice in our previous example that we put our feature flag in the entry point to the two screens, rather than adding all the information into one screen and deciding what to show and hide within the screen.

We structure our feature flags on multiple levels: we have global, user and override flags. Global-level flags reveal the feature for all of our users, user-level flags reveal the feature for individual users, and override flags reveal the feature to a percentage of our total users. As we’ve grown, we’ve started rolling almost all features over the course of a few days using override flags which helps us to catch any last minute errors before it becomes unmanageable for us.


Benefits


We can build a feature and test it in production without exposing it to all of our user base, this is very powerful in that we can be certain in the feature before rolling it out and we know that we can avoid having to merge code with other teams when working on a shared screen as our feature flag separates the new logic to the existing code. We also have the added advantage that given the review time lag on the app stores, this gives us more flexibility to avoid hotfixes. 

Our build process rolls out the feature flag to an increasing percentage of users, which enables us to identify issues sooner and then stop rolling out a feature if we need to or we can quickly apply a hotfix without our entire user base having access to a broken feature.

We can also utilise A/B testing, an approach for sending users through two different journeys in the app and comparing the outcome through analytics to determine the more successful journey. We combine the analytics in each screen that users see to make informed product decisions. Because we split out screens and user journeys through different feature flags, we can enable the feature flag for a select percentage of users and compare the success rates of each journey. 


Weaknesses


Once you’ve set up your first feature flag, it becomes really easy to add more and it can spiral into creating more than necessary. Having a lot of feature flags comes with a cost to maintain them within the codebase and having to add extra tests to cover all possible paths can be cumbersome.

Feature flags should introduce a temporary behaviour and be replaced completely when necessary, there is certainly an overhead for having to remove the code which is no longer required once the feature is enabled for all users.

These can be mitigated by making feature flag management part of the release process, when a feature flag is enabled globally then the code that checked for that flag should be removed. You can add an expiry date on the flag to stop the feature being used after a certain time frame, this gives time to develop the feature while also making sure that the roll out does not get so delayed that the flag loses its intended purpose.



Sorry, we had to hide what's coming up ;-)




Best Practices

1. Ensure the configuration of the flags is right for your use case:


  • Evaluate what is required from feature flags in your own system before adding them. Do you need to be able to develop multiple features in parallel which could be on the same user journey? 
  • Do you need to roll out a feature to all users at once or be able to slowly allow a growing percentage of users access over time?
2. Place feature flags at the start of a user journey:
  • Aim to use feature flags to split entire journeys for a user rather than small elements within a page so that removing the flags will be an easier clean up process and keep the code separated when developing the new feature

3. Consider naming conventions up front:
  • Use specific names so the feature is understood across the whole development team, for our previous example we called the flag `RedirectToHomepageOnLogin` rather than something like `NewScreen` because it describes what we’re doing specifically. At Freetrade, we also combine the client into the feature flag name (adding `Android` or `IOS`) so we can enable features in individual clients.
4. Make removing a feature flag part of the rollout
  • When setting a flag to be enabled for every user it is no longer required, so make removing the feature flag from all parts of the codebase part of your rollout strategy; to be even more diligent you can give the flag a lifespan to make sure it does not live beyond its intended purpose.



Conclusion


You can see how powerful of a concept having feature flags in our code is - it allows us to develop faster, roll out features with fewer crashes and enables us to safely test in our production environment. 


We see having feature flags as an inventory to our codebase, we utilise them in every new feature we add as part of our development cycle and we make them part of our rollout process so we do not get overloaded with legacy code. 

We're always on the lookout for engineers to help build our mobile apps. If the above sounds fun, check out our careers page to find out more.


Building Freetrade

Introducing Freetrade for iPad

How we developed the app with a brand new UI.

2/3/2021

|

Alex Curran

Building Freetrade

Stream partitioned data from Firestore using Async Iterators in Node.js

Software Engineer Mathias Dewert talks about dealing with the issues that come with rapid growth.

26/2/2021

|

Mathias Dewert

Building Freetrade

Using lint rules to prevent bugs

Principal Software Engineer, Alex Curran, shares more about our process to prevent bugs as we build our mobile apps.

22/1/2021

|

Alex Curran

Building Freetrade

Data Infrastructure at Freetrade

Principal Data Engineer Benen Cahill shares our process for data here at Freetrade.

13/1/2021

|

Benen Cahill

Building Freetrade

Nine books every product designer should read

Principal Product Designer Caitlin Rich shares her top reads to help inspire good design and keep user experience front of mind.

14/1/2021

|

Caitlin Rich

Building Freetrade

120 US real-estate investment trusts are here

Including some big name S&P 500 companies

21/12/2020

|

Sam Poullain

Building Freetrade

The road to 500 serverless functions

Software Engineer Theo Gregory shares how we use serverless to speed up deployment.

17/12/2020

|

Theodore Gregory

Building Freetrade

Changing an industry with the help of a 250,000 person product team

Senior Product Manager, Jani Kiilunen, shares how we work with the Freetrade community to build the product

17/12/2020

|

Jani Kiilunen

Building Freetrade

A stock-ing filler: massive market cap ADRs, biotechs, and ETFs

Including SAP, Credit Suisse, Ryanair, Trivago

25/1/2021

|

Sam Poullain

Building Freetrade

Earn 3% interest on cash in Freetrade Plus

Brand new for Plus members

6/1/2021

|

Sam Poullain

Building Freetrade

Lessons learnt with Cloud Firestore

Freetrade Head of Engineering, Invest, Tim Drew, shares how we scale our platform using Cloud Firestore

21/12/2020

|

Timothy Drew

Building Freetrade

Remote onboarding to a new job

Freetrade Software Engineering Manager Rokey Ge shares his virtual onboarding experience.

10/12/2020

|

Sam Poullain

Building Freetrade

Referring friends and earning free shares just got even easier

A big improvement to Free Share is here.

10/12/2020

|

Sam Poullain

Building Freetrade

Investment fees calculator

See how Freetrade compares to other brokers.

2/3/2021

|

Sam Poullain

Building Freetrade

Building Reactive Applications at Freetrade

Senior Software Engineer Jimmy Thompson takes you through the three layers of the Freetrade app

10/12/2020

|

Building Freetrade

600 brand new stocks, including David Beckham's Esports team

Gold miners, Twinkies, McDonald's and more.

10/12/2020

|

David Kimberley

Building Freetrade

Increasing the US order value limit

A new limit of £25,000 for US stocks.

10/12/2020

|

Sam Poullain

Building Freetrade

Brand new ETFs on Plus

Including fixed income, investment-grade and government bonds.

25/1/2021

|

Sam Poullain

Building Freetrade

How your product vision could put a human on Mars

Freetrade VP Product Duncan Leslie on vision, strategy and measuring success.

10/12/2020

|

Duncan Leslie

Building Freetrade

Stock fundamentals are now on your app

Market cap, dividend yield, and P/E ratio are here.

10/12/2020

|

David Kimberley

Building Freetrade

Introducing the time-weighted rate of return

Compare your performance against a global benchmark

10/12/2020

|

David Kimberley

Building Freetrade

It’s raining stocks: 500 new investment opportunities on your app now

10/12/2020

|

Viktor Nebehaj

Building Freetrade

The Freetrade Christmas List 2020

Everything we plan to add to your app before the holidays.

25/1/2021

|

Sam Poullain

Building Freetrade

Optimising cold-starts with Google Cloud Functions

Freetrade engineer Simon Poole talks about overcoming some serverless infrastructure challenges.

10/12/2020

|

David Kimberley

Building Freetrade

Over 450 brand new stocks

From Papa John's to Zambian cattle farmers, we've added a wide array of new stocks to the Freetrade universe

10/12/2020

|

David Kimberley

Building Freetrade

Celebrating Black History Month at Freetrade

Freetrade Talent Sourcer, Isabelle Atunrase, shares why we should all celebrate Black History Month, and some of the ways we’re getting involved here at Freetrade.

10/12/2020

|

Sam Poullain

Building Freetrade

100 new ETFs from iShares, Vanguard, VanEck, and more!

Our biggest addition of ETFs yet.

25/1/2021

|

Alex Campbell

Building Freetrade

User Story Mapping - How we keep a focus on value

Freetrade Senior Product Managers Anant Sangar and Glenn Drawbridge have been busy working on limit orders and SIPPs. Here, they chat through how use User Story Mapping.

10/12/2020

|

David Kimberley

Building Freetrade

400 brand new stocks, including 200 exclusively for Plus

More of what you want.

10/12/2020

|

Alex Campbell

Building Freetrade

Event sourcing on Freetrade

Freetrade Senior Software Engineer Luke Smith talks about the nuts and bolts of our brokerage platform

10/12/2020

|

David Kimberley

Building Freetrade

New stocks coming to your free plan and Plus subscription

Introducing your expanded stock universe.

10/12/2020

|

Alex Campbell

Building Freetrade

Money-weighted rate of return

More ways to measure your portfolio performance

10/12/2020

|

Sam Poullain

Building Freetrade

Our first Open Banking integration is rolling out

It’s now even easier to add money to your Freetrade account

10/12/2020

|

Sam Poullain

Building Freetrade

How to land a role in Product Management

Freetrade Senior Product Manager Glenn Drawbridge shares his story.

10/12/2020

|

Sam Poullain

Building Freetrade

Announcing the Tesla free share winner

10/12/2020

|

Sam Poullain

Building Freetrade

Introducing Freetrade Plus

Find out what's inside, and request your invite.

2/3/2021

|

Duncan Leslie

Building Freetrade

Brand new stocks: fashion brands, fast food, biotech innovators, and another SPAC

Over 100 new stocks, including Kodak, La-Z-Boy, Tiffany & Co, and Crocs.

29/1/2021

|

David Kimberley

Building Freetrade

Meet our new Head of People, Amy Gilman

Amy joins Freetrade as our first Head of People.

10/12/2020

|

Sam Poullain

Building Freetrade

Brand new stocks: fashion brands, gold miners, and SPACs

100 stocks inc. Avis, Tripadvisor, Goodyear, AMC Entertainment, Denny’s

29/1/2021

|

David Kimberley

Building Freetrade

Your new order experience is here

The first of many additions to order types.

10/12/2020

|

Sam Poullain

Building Freetrade

Brand new stocks: fresh IPOs, Latin American stocks, and investment trusts

75 new stocks including Ericsson, Yelp, Gfinity, Youdao

10/12/2020

|

Sam Poullain

Building Freetrade

28 brand new ETFs and 70 new stocks

Country-specific ETFs, and stocks from Wendy’s to Columbia

25/1/2021

|

Sam Poullain

Building Freetrade

Brand new: ETFs, Korean telcos, Japanese app and Chinese airlines

100 brand new stocks and ETFs are here

25/1/2021

|

Sam Poullain

Building Freetrade

Cloud computing, ETFs, UK stocks and brands from AB Inbev to Dominos

This week's 100 new stocks and ETFs might be the best batch yet.

25/1/2021

|

Sam Poullain

Building Freetrade

Brand new stocks: Banks, planes, trains and automobiles

Ferrari, Honda, Canadian Railway, United Airlines, Canadian banks, ETFs, and more

10/12/2020

|

Sam Poullain

Building Freetrade

90 brand new stocks have landed

You can now own a piece of Ed Sheeran

10/12/2020

|

Sam Poullain

Building Freetrade

Buy weed (stocks) on Freetrade

Cannabis companies have arrived

10/12/2020

|

Sam Poullain

Building Freetrade

Perry Blacher, serial entrepreneur turned VC, is joining Freetrade’s board

The former entrepreneur will be Freetrade’s non-executive director

10/12/2020

|

David Kimberley

Building Freetrade

Meet the team: Renata Labude, Senior Growth Manager

Find out more about how Free Share works

10/12/2020

|

David Kimberley

Building Freetrade

Introducing more stocks on Freetrade

250 new US stocks have landed

10/12/2020

|

Viktor Nebehaj

Building Freetrade

Fractional shares: the rollout has started

You can now invest in a slice of US companies

10/12/2020

|

Viktor Nebehaj

Building Freetrade

Meet the team: Caitlin Rich, Principal Product Designer

Meet the person responsible for making Freetrade look cool

10/12/2020

|

David Kimberley

Thank you! Please check for your confirmation email.
Oops! Something went wrong while submitting the form.

Join the 25,000+ investors getting our take on the markets

Almost there! Please check your inbox to confirm subscription

Sign up for our newsletter

Download the app and start
investing now.