In today’s software development world, most of the time we use the agile methodology to develop software. In agile, we use continuous integration and continuous deployment (CI/CD) as a practice, where every line of code goes to production in seconds, sometimes even without a manual check by a person. Sometimes, this CI/CD approach may also introduce a feature that is not fully developed or even new bugs to the production environment.

The fear of “losing control” in the production environment prevents some large organizations from following CI/CD.

Wouldn’t it be great if you could decide which feature should be enabled in production simply by clicking a button, with no code changes or deployment? Here comes the feature toggle.

What is Feature Toggle?

Feature Toggles (often also referred to as Feature Flags) are a powerful technique, allowing teams to modify system behavior without changing code. In simple terms, a feature toggle is like a simple switch, when it’s on, software will behave in a certain way, otherwise in a different way.

Benefits of Feature Toggle

  • Speed: Feature toggles are especially useful for speeding up the development process when combined with Continuous Integration and Continuous Delivery. Rather than working on long-lived branches that become difficult to merge, work can be done in small pull requests that get merged frequently to the main code branch. Developers are more productive as there is less chance of merge conflicts, in case there is some conflicts occurs it’s get easily dealt with as the context of a change is still fresh in people’s minds.
  • Test it before production: With multiple environments, feature can be tested end to end even before it becomes available to wider users.
  • Mitigate Risk: If someone finds any problem with the changes, it can be easily reverted immediately without any new deployment.
  • Invisibility: One of the more obvious benefits of feature toggles is that they allow you to release new features that are still under development. Since each new feature is behind a toggle, it won’t go live until you decide to turn that toggle on.
  • Flexibility: Feature toggles make it easy to test assumptions.

Drawbacks of Feature Toggle

  • Complexity: Feature toggle introduces extra complexity to the codebase. When there are many feature toggles code becomes very complex to modify.
  • Lack of clarity: Sometime it becomes really hard to understand which features are actually running on production.
  • Dead code: We don’t always remove feature toggles that have been in use for a long time because of business priorities. The codebase will eventually have a large amount of outdated or dead code as these toggles are provided.
  • Auditability: Given that feature toggles are managed by external configuration, there is always confusion about the timeline for a feature going live in production.

Conclusion

Feature toggle is a powerful technique used by many big companies. It comes with many benefits and drawbacks. Too many feature toggles or long lived toggles add complexity to the code. It’s always suggested to keep feature toggles short-lived and small in number. Cleaning up feature flags is important to keep a codebase clean and balanced.

Originally posted on medium.com.