What Is Feature Flagging? Feature Flag Best Practices
Separate feature release from code deployment by leveraging feature flagging. With feature flagging, you can roll out features to select users, turn features off altogether when needed, and conduct A/B testing to inform future product direction.
Follow along, or jump ahead to the section that interests you most:
- What Is Feature Flagging?
- Why Use Feature Flagging?
- Feature Flag Best Practices
- Feature Flagging vs Feature Branching
- How to Manage Changes When Feature Flagging
What Is Feature Flagging?
Feature flagging is a technique that allows developers to turn features on and off as needed during the software development lifecycle. This allows teams to change system behavior without requiring corresponding code changes.
Feature flags (sometimes called feature toggles) are conditions that determine whether certain logic is available. These conditions can be toggled on and off; turning a flag on means the feature is available, turn the flag off and the logic is bypassed. Feature flags are also known as feature controls, feature toggles, and feature switches.
Use a version control software to accelerate development. Try Helix Core free.
Why Use Feature Flagging?
Feature flagging gives teams additional control over testing and audiences, which ultimately speeds up the deployment cycle. Some use cases for feature flagging are:
Simplified Branching Strategy
Feature flagging and trunk-based development often go hand-in-hand as different developers can be working on different features on the same branch and avoid conflicting changes through turning specific features on or off. This simplified branching strategy avoids scenarios like individual developers working in isolated branches and not integrating their changes frequently enough which can lead to unwanted release delays. It also allows you to continuously ship because teams working on incomplete features can simply keep them shut off until they are ready for prime time.
With feature flags, teams can quickly deploy software to users in a safe manner. Feature flags are a crucial component to the continuous deployment discipline. Features are separated from code deployment; that is, features can be released gradually, turned off if bugs are found, and turned back on again when fixed without impacting the deployment cycle.
Buggy features? Simply switch the feature flag off. This is helpful during testing—you can quickly roll back the feature if necessary. System performance issues? Simply switch off less critical features for a period of time until the performance issues are resolved. Concerned about how a new or revised feature will be received? Simply turn that feature on for a small subset of users and seek their feedback.
Get Started With VCS
Try Helix Core free today and see how you can accelerate your branching strategy.
Feature Flag Best Practices
As with any form of software development, you’ll want to follow best practices to ensure your code is clean and error-free. That may mean using feature flags with trunk-based development, using feature flags in conjunction with branching, or utilizing a different strategy all together.
Here are a few common feature flagging best practices:
Feature Flag Best Practice #1: Establish Naming Conventions
Eliminate confusion by having standardized naming conventions for your flags. This will reduce the chance of toggling the wrong flag and make for better version control and traceability.
Feature Flag Best Practice #2: Clean Up Flags Not in Use
It’s easy to create a flag and forget about it once you’ve moved on. Once a feature has been completely rolled out, or once a flag is no longer needed, be sure to retire those flags to reduce design drag in your codebase and to streamline flag management.
Feature Flag Best Practice #3: Monitor Control of Users
A benefit of feature flagging is that non-technical team members can access them. For example, the product team can assist in A/B testing. That being said, it’s important to control who has access and to what. Consider locking changes in the production environment or maintain a log of who has changed which feature flag.
Feature Flag Best Practice #4: Don't Overuse Feature Flagging
Feature flags are useful in some situations but aren’t one-size-fits-all. Feature flags are best for features that can be controlled from a small number of points in the code. Other use cases, such as refactoring, are harder to control with a flag. In these instances, consider using feature branching.
Feature Flagging vs Feature Branching
Feature branching allows multiple developers to work independently on changes, managed in their own independent branches. Developers work on smaller chunks of code, test in their isolated branch, and then eventually merge their changes back into the main codebase.
There are pros and cons to both feature flagging and feature branching. Feature flags, while good for segmented testing, can lead to messy code if they are overused, if they are not well-documented, or if they are not retired when no longer needed.
In feature branching, problems arise if merging doesn’t happen often enough. Feature branches that are not merged into the main codebase can result in numerous conflicts when the main codebase evolves faster than the feature branch does. However, feature branching is ideal for large scale projects, allowing developers to focus on small sets of changes in isolation from the rest of the team. It also allows for tighter control over what code is entering the code base—which can be a problem with feature flagging if flags aren’t used judiciously.
Feature flagging and feature branching can be used together to test in isolation and maintain control over releases. Together they lessen the risk of buggy code in the main code base with the option of integrating short-lived branches efficiently.
How to Manage Changes When Feature Flagging
Whether your term uses feature flagging, feature branching, or a combination of the two, you’ll need a version control system to keep track of your changes. With Helix Core –– version control from Perforce –– software branching best practices are built in. With Perforce Streams you can implement a robust workflow to guide development. You get higher-quality code, while keeping development productive. Try Helix Core free to manage traceability across your code and accelerate development.