Finding the best strategy to implement features in software development is a controversial topic. You find lots of discussions about whether you should use Feature Branches or Feature Toggles. When looking at some of the technological innovators you can find both strategies in action.
This article will not describe those strategies in detail, so you should already be familiar with them. In the following, I will provide some ideas why both strategies are a good match in different areas and which prerequisites are essential for both strategies.
When talking about Feature Branches, you quickly encounter the issue of merge conflicts. You can often read about the merge hell that arises from using Features Branches. Why is this opinion so present in the discussions?
Branches are developed independently from each other. That way, you can have several days or even weeks of independent development, which will most likely lead to merge conflicts. Therefore, it is recommended to keep Feature Branches as small as possible. If active development on a Feature Branch takes several weeks, the potential for merge conflicts rises drastically.
As a conclusion, Feature Branches should be merged after only a few days (in an ideal world one day at maximum). To achieve this, the scope of the feature should be reduced to a minimum. This requires careful planning of features and dividing large features up into several smaller features.
But what about Feature Toggles? Although Feature Toggles are mainly used as a release strategy, they may also be used as a strategy to reduce the risk of merge conflicts during development. You achieve this by commiting changes directly into the master branch that propagates to the other developers within a few hours.
But there are other challenges you have to overcome with Feature Toggles. If you keep lots of features disabled for a long time, you can easily lose control over all the available Feature Toggles. Therefore, it is recommended to use only a handful of Feature Toggles at the same time in your application. This can only be achieved by keeping the lifespan of Feature Toggles short, which in turn requires good planning to keep feature scope in check.
The most important aspect of both strategies is keeping your feature as small as possible. If you are not able to cut the feature down to a minium, you will have issues with both strategies.
Feature Toggles are often a good fit for public web applications. Their deployment is completely in control of the providing company. Examples of those applications are Facebook or Twitter. Continuous Integration and Delivery are essential to them, because the faster new features or bug fixes are available, the better it is for their product. Users can directly use new features. The Feature Toggle strategy integrates all changes directly and therefore fits well to the extensive usage of Continuous Delivery.
Using Feature Toggles requires a lot of discipline. You have to be aware of adding temporary technical debt to your application, because the toggles have to be applied somewhere and cleaned up again when the feature is complete. You also add unfinished code to your application. This code is not reachable as long as the Feature Toggle is deactivated, but it is still available in production. As soon as multiple Feature Toggles are active, the different toggles have to be tested in combination. Perhaps they work fine individually, but will cause issues when working in combination. So it is important to have only a very small amount of toggles active, as mentioned before.
For big applications, though, it is not possible to only develop on three to five features at once. More features have to be developed in parallel. The solution to this is a well-structured modular application. The modules must be as independent of each other as possible. Microservices are a great approach for such a modular structure.
Feature Branches is a strategy applied during development to isolate the development and testing of a single feature or bug fix.
In my opinion a huge advantage of Feature Branches is the tool support for code reviews. Tools like Bitbucket or Gitlab provide great functionality to review Merge/Pull Requests. This helps in assuring the completeness and quality of the feature. There are surely pre-commit hooks that can also be used when working directly on the master branch, but I am at least not aware of such a wide and mature tool support as there is for Feature Branches.
Sometimes Feature Branches are blamed to not fit into Continuous Integration, as development is done on the isolated branch and not all changes are integrated with each other directly. I think this argument is not valid when the prerequisite of small scoped features is applied. Even though a short isolated development is done on a branch, it still gets integrated quickly and I would still call this Continuous Integration.
The following picture sums up the differences between the two strategies.
Using Feature Toggles as the main strategy has high demands on your team’s experience and discipline (Dev, QA & Ops). On the other hand, Feature Branches are easier to handle and integrate into existing development and release processes.
Whether to use Feature Branches or Feature Toggles depends on the type of application you provide. In some cases it may absolutely make sense to combine Feature Toggles and Feature Branches.
Our recommendation would be to start of with Feature Branches and establish a lean development and release process (i.e. Continuous Delivery). When your team gathered enough experience you could start thinking about utilizing a combination of Feature Toggles with Feature Branches (e.g. for A/B Testing). The first Feature Toggles should be limited in scope and amount to avoid big „tremors“ in your processes. If your team (and your management of course) feels the need to change gears, you can switch to fully using Feature Toggles as your main development and release strategy step-by-step from there.
While this article represents our ideas regarding Feature Toggles and Feature Branches, we would be happy to learn about how others think about those topics. Please feel free to leave a comment on this page and tell us about your experiences and/or opinions about Feature Toggles and Feature Branches.