Feature Toggle — The Fancy “if”

Chandan Kumar
3 min readSep 20, 2021

Feature toggling is a powerful pattern which allows you to change the functionality of your application without touching your code. You can enable or disable feature in quickest possible manner using this technique.

I sometimes wonder how this simple concept of an if statement around a feature makes it so powerful that it’s now so common across the industry and application and almost all the application which uses CI/CD (continuous integration and continuous deployment)as their deployment process uses it.

Image source — https://developpaper.com/add-feature-flag-to-your-asp-net-core-program/

It makes life easy while achieving CI/CD at it’s best where each of your code gets deployed to prod not having feature toggles is not an option. Any breaks in the newly deployed code can be disabled quickly using it, without having to redeploy the entire application.

At it best feature toggle is just a fancy if that wraps around a feature to make it enable or disable, which helps in disabling any feature in case of a bug or failure caused due to that feature.

After sometime when you’re sure your feature works fine the best practice is to clean up the feature toggle so that unnecessary code get’s removed from your code.

Every pattern comes with some tradeoffs hence the feature toggling;

  • There are extra effort required to add the feature toggle
  • Add extra unit testing for feature on/off scenarios (obvious)
  • Requires additional cleanup process.
  • If add so many of it then it will be hard to maintain and clean.
  • If cleanup is not done on timely basis it will add lot of extra code in codebase.

There are also some problems comes with it, in most of the cases feature toggle is a table in the database values of which gets updated via api endpoint provided by the application’s feature toggle endpoint.

Access to production database is not always a good idea and in cases where you don’t have access to production, you’ll need extra efforts putting some admin UI or something similar to it to achieve the same results.

In an ideal world any new feature goes to prod behind a toggle and then removed after sometime which is called toggle cleanup. But is real world it’s not something which always happens. Developer looks at the feature and see if it’s worth it to add feature toggle here for this simple feature? Those questions will come to you and you’ll have to decide.

It reduces the risk, and gives a confidence to go to prod quickly, especially for the project where there’re multiple teams involved and you’ve to deploy things till prod it will help you to push your code till prod without enabling the feature for the users.

Feature toggling enhances CI/CD by making “continuous” more achievable. The feature flags and feature toggles are a key component of the implementation of continuous delivery, allowing the separation of feature rollout from code deployment. Incomplete features can be merged into the production codebase but hidden behind feature flags.

--

--

Chandan Kumar

Developer at /thoughtworks | Kotlin | NodeJs | ReactJs | Docker | Dev Practices | Agile | Java | Spring Boot | Consultant | Delhi, India | 👨‍💻 📚