Getting to Continuous Deployment in Django: Feature Flipping

This post is a first in a series of posts about our move towards continuous deployment using Django.

Continuous deployment is a process by which code that is written for an application is constantly deployed into production without manual intervention. This allows us to be agile, to quickly innovate, and more importantly, to bounce back from any grave errors, unscathed.

When it comes to building new features, this can involve merging feature branches, rigorous code review, testing, and deployments, before you can test it out on a live environment. Every subsequent release to different groups of users would require code changes, and deployment.

This can be avoided by employing feature flipping, which is an essential step towards achieving continuous deployment in your application.

So what is this feature flipping thing, anyway?

In its most basic form, you can think of it as applying an on/off switch to a piece of code in your codebase thereby releasing or rolling back a feature.

This allows you to constantly push new code for features that you’re not quite ready to release to any of your users yet. And when you’re ready, you can do a gradual rollout of the feature - to various groups of users. All, from a simple dashboard, with a single click.

Analysis of Django Feature Flipping Libraries

There are a number of open source libraries in Django that can be used for this purpose. Recently, we analyzed our various options - the two biggest contenders were Gargoyle and Django Waffle. Following is the result of our evaluation:

Ease of Installation:

Both libraries can be installed via pip or easy install and have to be included in your list of INSTALLED_APPS. Waffle also requires you to add a MIDDLEWARE and a CONTEXT_PROCESSOR for templates.

Switches and Flags:

Both libraries support applying a switch to a piece of code via a conditional, a decorator to a view or template tags in Django.

Gargoyle, however, allows you to set conditions to your switches such as percentage of users, groups or specific users. It also allows us to associate percentages with users IP address - release it to 30% of NY, 10% of chicago etc.

Waffle takes a different approach to this and uses Flags, which when activated can be applied to groups, specific users, or a set percentage of users. Although flags can be triggered in every way that a switch can be, they are tied to request objects while switches are named booleans in the database. The flipping uses cookies and is session based so ‘smart’ users can get around it but this can be avoided by adding a user to a group when they initially encounter the feature, and enabling the feature for that group.

Usage in Javascript:

Waffle allows us to use switches and flags in javascript by including the appropriate JS file and using the global waffle object.

if (waffle.flag('some_flag')) {
   // Flag is active.
} else {
   // Flag is inactive.
if (waffle.switch('some_switch')) {
   // Switch is active.
} else {
   // Switch is inactive.

Gargoyle does not currently support Javascript.

Admin Frontend:

Although not necessary, Gargoyle encourages the use of Nexus for the Django Admin frontend. If you choose not to do this however, you will need to enable the discovery of modules in your

import gargoyle

Final Thoughts

As mentioned earlier, both libraries are strong contenders in the Django Feature Flipping community and can be easily forked on Github to add extra functionality if required, instead of reinventing the wheel.

Finally, while feature flipping definitely has its upsides it can have its disadvantages. Although this means less merges, continuous integration and frequent and smaller deployments, constant maintenance of the codebase is necessary once a feature is completely released so you don’t have to maintain multiple versions.

Nitya Oberoi is a Developer at Yipit.

To find out about future posts, you can follow along using: