Ever had this scenario?

We have new changes we want to place on the website. The team pushes the changes live. All of a sudden, the site goes down. People are scrambling to figure out what went wrong.

Can we safely deploy changes for new features?

YES!

People have the notion that a change on a website occurs once the deploy finishes. Generally, this is true, but you can separate a feature’s deployment from its release.

Feature toggles can help. A feature toggle is a flag in the code that will allow a user of your software to use the new feature. These flags can affect how the request from the user gets handled or what actually gets displayed on the screen.

For example, let us say you wanted to try and upsell your customers with a few more products on the cart page. Once the feature is complete, add a feature toggle to your website that will show the upsell feature for targeted users. You can gradually increase the targeted customers that have the upsell feature until all customers are using it.

This is extremely useful for quality assurance purposes. The testing group sets the toggle so they have the new feature. Once the new feature is on, the testing group validates its correctness. If the testing group gives the feature a thumbs up, flip the switch for all users so they can now enjoy the feature.

Websites like Facebook have been using feature toggles for years. It’s a handy technique to release new features in the software and perform A/B testing for a new design. As mentioned above, toggles have the ability to quickly turn a feature off when something goes wrong.

Trade offs

There are a few trade-offs to consider before using this.

  • You manually turn on a toggle for the feature to show up on the website. This seems obvious, but I have forgotten multiple times when a feature wasn’t showing up.
  • Toggles cause the site to have multiple variations of pages and even sections of the site. Multiple variations compound figuring out broke.
  • You have some extra house cleaning in the code base when you are removing the toggles.

Shout out

Any Django developers reading this can use the django-waffle package. It provides mechanisms to place the feature toggles in a template, as a view decorator or inside the view. You can also turn each toggle on for an individual user, group, a percentage of users or in a rollout manner. There is even a template tag to help with use waffle’s feature toggle flags in JavaScript.

Conclusion

Any new feature on a site should be tested and easy to turn on and off at the flip of a switch. Feature toggles make it very easy to turn a features on and off. They can also get used to release a feature to a small subset of users and quickly turn off the feature if something goes wrong.

If you found this useful I also have a personal programming blog at www.ericbulloch.com