Feature flipping is a technique by which a block of code is conditionally included or executed for a user.
This can look like a site wide on/off switch, a more complicated set of filtering logic including randomization, or somewhere in between.
It’s a must-have strategy in your toolbox if you’re working with a SaaS product or any other kind of customer-centric site.
Let’s motivate this claim!
Feature flipping adds extra code to your project and it requires its own maintenance. You’ll need to remove code that you’ve added just for the feature deploy, and it can complicate testing.
And yet in many situations it’s more than worth this minor hassle.
Depending on how it’s deployed, feature flipping can:
If you’ve had a product in the wild for a while, customers will be used to how things look and work, whether you like it or not.
By turning on a new feature or changing how one works for a select group of customers, you can gather feedback - directly or indirectly - to make course corrections so that the full deployment is well received.
With almost every legacy Django project we’ve encountered, deployment is always a pain point. It might be for technical reasons, for cultural reasons, but whatever the reasons feature flipping allows for much for iterative deployment with an “off” switch that beats deployment rollback any day of the week.
There are several ways of _implementing _feature flipping in a Django project.
If you’re going to be implementing feature flipping more than once, a third-party app is probably your best bet. We’ve used Django Waffle on several projects and it probably fits 90% of feature flipping uses beautifully. Gargoyle works too, with some additional under-documented filtering features.
And yes, you could roll your own. It’s very unlikely you’d need to do this, but if you need more power than Waffle offers and don’t want to use Gargoyle then this is your next avenue.
The main reason to write your own is if you need more expressive conditionals and need these to be available in an intuitive way for non-technical users in the admin. E.g. Waffle lets you select for 1 or more individual users or groups (auth.Group) if you want. I was reminded of this in a blog post about feature flipping with Waffle and I am going to tell you that using groups will _work _but is not a great idea.
Look, it’s not going to break anything, but if for any reason you’re using groups to manage permissions - the purpose of groups - then this could cause serious confusion. A “better” filter would be based on something like _tags _on a user profile or customer account model… but now we’re talking custom development.
I should say a word about A/B testing before wrapping this up, because feature flipping is a core component of A/B testing (but remember, not vice versa).
There _are _tools for A/B testing in Django and no we haven’t used them. In the past we researched these and found that for the purposes of app-integrated A/B testing the feature flipping tools were more than sufficient. Waffle provides some randomization filtering, and if you really want to get funky you could chain a switch or feature flag with some custom middleware to add more fine grained randomization.
(And make sure you’ve got the numbers to justify the test!)
On today, off tomorrow,
Learn from more articles like this how to make the most out of your existing Django site.