Rollout is a popular Ruby gem that helps manage the sometimes tedious nature
of feature flagging. It was originally architected with Redis as a dependency.
While we do love Redis immensely, we felt now was not quite the time to add yet
another piece of infrastructure to our application. Thankfully, a semi-recent
update for Rollout removed the Redis dependency and allows the end user to use
any key-value store. The only requirements are that an instance of the store
needs to respond to the get, set, and del methods.
Given that we are not ready to add another piece of infrastructure to our stack,
we decided to create a wrapper for PostgreSQL’s Hstore feature.
We created a new ActiveRecord model called FeatureFlag that has a singular
attribute (migration and model below).
So far, so good. We didn’t necessarily need an empty AR model and could have
simply written some SQL statements inside of some PG connections, but most of
our business logic resides in AR.
Implementing the Store
Now for the fun part! As stated above, an instance of our store needs to be able
to handle the get, set, and del methods appropriately. Just from perusing the
rollout codebase, the methods are defined as the following:
- get takes a key argument and returns the value for the key
- set takes two arguments (key, value) and creates or updates the key-value pair
- del takes a key argument and deletes the key-value pair
Below is the code that handles these scenarios.
It is relatively straightforward. We really utilize ActiveRecord a ton here but
I think it’s an okay decision given our data structures above. Like any engineer
that adheres to the values of testing, I also threw some tests in to cover the
various scenarios for the RolloutStore. They are below.
We wanted to create something with as small a footprint as possible without
having to add Redis to our stack for feature flagging. This little piece of
software seems to fit exactly that. The code is available on