Introduction blog post
I absolutely don’t think human/manual QA gates should be involved in between the writing of code and its being live. To avoid breaking things every time and to have an early cutoff system, you should use feature flags.
There are a lot of systems available on the market to manage your flags, like LaunchDarkly or UNLEASH, that have Golang support — but this option is expensive, and you have to host a server somewhere to manage your flags.
From this starting point, I came up with the idea to create a simple library with only one file in the back end. This file can be stored in different places (AWS S3, GitHub, an HTTP endpoint somewhere, etc.). This is the only thing you have to host — all the decision logic stands inside the Go module.
Why a new solution?
There are some solutions available for Go to manage feature flags. I can classify them into two categories:
- You need to run a specific service: markphelps/flipt, checkr/flagr, Unleash/unleash, vsco/dcdr, etc.
- You need to have a database: xchapter7x/toggle, AntoineAugusti/feature-flags, etc.
All of these solutions are great and have a lot of features, but I was a bit worried about having a full setup with things to install before doing feature flags on a basic service.
I don’t want to host/maintain/monitor a full feature-flag system if my needs are really small.
So I decided to make go-feature-flag, a simple and easy-to-implement feature-flag system, with no back end at all except a shared configuration file you can store anywhere (S3, GitHub, HTTP endpoint, etc.).
The goal is to experience the usage of feature flags without a complex solution, and if you end up liking it and need a more advanced pattern, you can go to any open-source solution or SaaS solution — like LaunchDarkly, for example.
How Does It Work?
How this Go module works is easy. It just reads the shared file every x seconds and gives you a way to get the value of your flag in the type you expect.
As you can see, what go-feature-flag is providing is a way for you to keep in sync with the feature-flag config file. It also allows you to evaluate the flag for your users.
A rule system based on nikunjy/rules allows you to specify complex rules to apply the flag only for a subset of your users.
The percentage allows you to select which percentage of users will get the true value, but I’m sure you wonder how the repartition is done. It’s really easy — we’re doing a hash of the key of the user with the flag name used as a salt (it guarantees that the repartition isn’t always to the same users).