Feature Toggles

You might have also heard about this as Feature Flipping or Feature Flags. No matter which expression we use, they are all based on a mechanism that permits you to turn on and off the features of your application. This is very useful when all code is merged into one branch and you must deal with partially finished (or integrated) code. With this technique, unfinished features can be hidden so that users cannot access them.

Due to its nature, there are other possible uses for this functionality. As a circuit breaker when something is wrong with a particular feature, providing graceful degradation of the application, shutting down secondary features to preserve hardware resources for business core operations, and so on. Feature Toggles, in some cases, can go even further. We might use them to enable features only to certain users, based on, for example, geographic location or their role. Another use is that we can enable new features for our testers only. That way, end users would continue to be oblivious of the existence of some new features, while testers would be able to validate them on a production server.

Moreover, there are some aspects to remember when using Feature Toggles:

  • Use toggles only until they are fully deployed and proven to work. Otherwise, you might end up with spaghetti code full of if/else statements containing old toggles that are not in use any more.
  • Do not spend too much time testing toggles. It is, in most cases, enough to confirm that the entry point into some new feature is not visible. That can be, for example, a link to the new feature.
  • Do not overuse toggles. Do not use them when there is no need for them. For example, you might be developing a new screen that is accessible through a link in the home page. If that link is added at the end, there might be no need to have a toggle that hides it.

There are many good frameworks and libraries for application feature handling. Two of them are the following:

These libraries offer a sophisticated way to manage features, even adding role-based or rules-based feature access. In many cases, you aren't going to need it, but these capabilities bring us the possibility of testing a new feature in production without opening it to all users. However, implementing a custom basic solution for feature toggling is quite simple, and we are going to go through an example to illustrate this.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.163.175