Playing with Flipper
I want to have a Feature Flag system in my Ruby on Rails apps, where a production system can have features changed without another code deploy. Some use a user interface to change values, some give an API to roll your own, some expect you to have console access.
In this article, I play around with Flipper, a Ruby on Rails gem that provides a way to toggle features on an off.
I want to understand how Flipper works and answer these questions:
- Can I flip parts of code on and off?
- Is there a user interface to do this?
- Is the system so complicated that only developers can access?
- Is the system easy for developers to incorporate into their work flow?
These are probably my big concerns in incorporating feature flags in systems I work with.
A team member recommended Flipper as they used it previously. I also like the fact it is recently updated and there is a dedicated user interface component.
I looked at their test suite, this is impressive. The Flipper team takes their code quality seriously.
As much as I want to “TDD” everything, this is not one of those times. Doing test driven development requires one to know how to get to the goal. In this case, I kind of do not, I have an end goal in mind, but not how to get there.
So, I want to just play around with Flipper, see how it feels, does it fit my needs, how different is my mindset vs. the frameworks?
At the same time, I will make this into structured play, so others can gain the benefit of my “play”.
All code can be found here
- System that can run Rails 5.1. I am using Ubuntu 16.04
- Or start with this vagrant setup
At the time of writing, I tried Flipper with Rails 5.2.2 but ran into issues. Downgrading to Rails 5.1 alleviated problems I had.
Get Rails Setup
If you have Ruby on Rails 5.1 installed, skip to the next section.
Tip: If the system has multiple versions of Rails installed, to use different version of rails: rails _version_ optiosn (i.e. rails _188.8.131.52_ --version )
Modify the Gemfile
In the Gemfile, perform the following:
$ bundle to install the additional gems
Configure Flipper to Start up
Create an initializer file:
configure Flipper on start up:
Make Flipper UI Accessible
To take advantage of the Flipper dashboard, in
change the contents to:
This will show Flipper’s dashboard when loading URL: http://localhost:3000/flipper.
Start Your Rails
With all the pieces for Flipper in place: initializer and routes entry, let’s start Rails:
and open a web browser to: http://localhost:3000/flipper to see:
Yup, gotta love Blank Space! ;-)
There are two ways to add a new feature to the Flipper user interface list: directly through the user interface and through code.
To include a new feature, just hit: “Add Feature” and type one out:
In playing around, I seeded the feature list in the Flipper user
interface through the
config/initializer/flipper.rb file by adding
new features using the following code:
Loading the Flipper user interface now lists:
Incorporating with Code
To use the feature flags registered with Flipper in code, I’ll try it
out with a basic endpoint:
Add the appropriate entry in the
and edit the
app/controllers/version file to have:
To test out, let’s make a curl request:
From the Flipper user interface, register the
beta feature flag and
set it to enable perform the same request again:
Tada~! So magical.
After playing around with Flipper and it’s user interface, I have found out how to:
- configure a new Ruby on Rails application with Flipper
- add new feature flags through the UI
- add new feature flags in code
This solves the initial questions I had:
- Can I flip parts of code on and off? Yes, by using
- Is there a user interface? Yes, by going to
- Is the system so complicated that only developers can access? No, through the Flipper user interface, one can see registered feature flags and add their own.
- Is the system easy for developers to incoporate into their work flow? Requires research.
I spent most of this article setting up Flipper and answering the first set of questions, I would like time to explore this and other features of Flipper in another article.