Introduction
In the dynamic landscape of mobile app development, delivering a seamless user experience while keeping up with evolving requirements can be quite a challenge. Feature flags (also known as feature toggles or switches) have emerged as a tool to address this challenge. In this blog post, we’ll delve into the concept of feature toggles and explore what are the implementation option in the mobile world.
Understanding Feature Flags
Feature toggles are a development strategy (technique?) that allows the development team to enable or disable certain features or parts of a mobile application with/without altering the codebase. This means that you can keep features hidden from users until they are fully tested or ready to be released. Feature toggles play a crucial role when you are having trunk-based development in your team – they allow you to develop new features and merge them to the trunk while making the feature unavailable to users. In other words, even though the code might be released, users won’t be able to use the feature unless you turn it on.
Benefits of Feature Flags in mobile
- Reduced Risk: hiding incomplete feature behind feature flag, reduces the risk of introducing breaking changes in your production.
- A/B Testing: once you get the app in production, you can enable new features among different user groups, helping you gather user feedback.
- Hotfixes and Rollbacks: let’s assume after release, you notice a bud in the new feature. Feature flags allow you to quickly disable the problematic feature and prevent users from using it. No need for additional release!
- Feature Development: feature flags encourage feature-driven development – the team can work on a feature in isolation without disrupting the main development flow.
- Feature Control: your product strategy might require certain features to be available to certain users. eg. Users from company A should have access to feature FA & FB, and users from company B should only have access to feature FB. This requirement may change as the sales department is working hard and maybe company C will acquire your product and they will use feature FA. You can obviously hardcode all those companies in your app code. You can also implement a feature flag with a filter that will allow certain users to use the feature.
Implementing Feature flags in mobile
As you may know, I am .NET developer mostly knowing Xamarin. In Xamarin we have several ways of implementing feature toggles
- Conditional Compilation: dotnet allows you to use preprocessor directives such as
#if
DEBUG and#endif
to conditionally compile code blocks. This is a really low-level feature flag technique. It will only enable you to include or exclude specific features based on compile-time variables. - Configuration Settings: within your app, you can create a mechanism based on app settings that will allow users to enable the features on their own. This might be handly if you would like your users to be able to enable certain features on their own (eg. stakeholders or testers)
- Third-party flags: there are 3rd party like LaunchDarkly or Azure App Configuration, that offer feature flags solutions. Among the functionalities, you can work with advanced features like targeting specific user segments and gradual rollouts. In my opinion, those are really handy as they are fully remote and they allow non-technical users to toggle the flags. No code needed to toggle the flag!
note: if you are using ReactNative, AppCenter has CodePush functionality that you might be convenient for you.
Best Practices
- Keep your codebase clean: Regularly review and remove unused toggle-related code to maintain codebase cleanliness and readability.
- Don’t reuse flags: especially in mobile development, you can’t be sure what effect it might have on the users. The fact that you were not touching the flag for 2 years, does not mean someone is not using it in their app.
- Don’t get too confident – test: there is a risk that feature flags might make you too confident. “I hide it behind a feature flag, there is no need to run regression tests. Let’s release”. It may happen that you configured your flag badly and it won’t work (that happened to me once 🙈). The fact that something is behind feature flags, doesn’t mean you should not test it.
Outro
In modern development, feature flags in mobile, offer a strategic approach to managing feature releases, minimizing risks, and maintaining a smooth user experience.
As I showed you in this blog post, these flags can be implemented through a variety of techniques – from pure code to remote config. I will show you how to implement them in upcoming articles.
If the topic of feature flags has piqued your interest and you’re eager to learn more, I recommend delving into Martin Fowler’s article for further insights.