What Is Feature Flag and What Problem Does It Solve?

Introduction

Feature Flag = Switch used to manage features in programs

I remember in a project that used Git Flow to manage product releases. The entire team spent months building a feature, but as time passed, it diverged more and more from the continuously ongoing main branch, ultimately requiring significant effort to synchronize the progress of both. It was after that incident that I came to recognize the concept of Trunk Based Development🔗, which mentions that Feature Flags are a great technique to reduce the risks and control levels of feature rollouts.

Why do we need Feature Flags?

There’s a saying: “Writing code is like building a church; once it’s done, we start praying.” This reflects the developers’ anxiety and fear regarding deployments. The simplest model regarding deployment is to deploy the latest progress at any time, but this black-and-white mode also creates some problems:

  • Synchronized updates: The product update cycle is two weeks, but a feature needs three months to complete. How to ensure everyone is working on the mainline without exposing a half-finished feature during release?
  • Deployment flexibility: Changes can severely impact users…
    • Disaster management: If something goes wrong, how can we quickly roll back? Can we gradually roll out features?
    • Feature allocation: Different timing (holidays) and users (different levels and types of users) have different feature needs. How to manage these?
    • Real-time feedback: New features need to be tested by real users to get the most real feedback.

Implementing Feature Flags can solve these problems by separating “deployment” from “release,” improving the experience.

Practice of Feature Flags

Feature Flags can be as simple as manually changing code or a simple logic check based on environment variables or relying on external states and services to change the program’s behavior. The key point is how to store the status?

LocationDifficultyResponse SpeedUpdate SpeedCostFlexibility
In CodeSimpleFastSlowNoneHigh
Environment VarSimpleFastSlowNoneLow
DatabaseTroublesomeSlowFastNoneHigh
SaaSSimpleSlowFastPaidHigh

Feature flags are a simple and understandable concept, but managing them at an enterprise scale is quite challenging🔗, and there are many best practices🔗 to explore.

Conclusion

Developers should naturally be quite familiar with the concept of Feature Flags, as common version control strategies today advocate for the concept of Feature Branches. However, Feature Flags discuss how to better improve the release experience based on existing pain points. As project scales increase, this problem will need to be addressed sooner or later.

You can understand the mature form of this strategy from ready-made services:

Further Reading