How to save the day with Feature Flags
You probably have heard of feature flags before. In case you haven't, they are a way to control the visibility of certain features in your application like this node index.js --awesomeMode
. But most web developers probably haven't thought about using them in their projects. Here is why I think you should.
What makes production deployments scary
In case you weren't responsible for deploying large production application before, let me tell you, it is nerve-wracking. Sometimes it works on your local machine and it also passes the CD/CI pipeline but somehow a small little bug sneaks into production and every user is affected by it. You slowly start to realize that something is off and maybe you get the first error notification here and there. But you did everything right and you're sure about it, right? Right? You open all your dashboards and you open all your logs and you start to sweat.
This is when you go into a flow state, a panic induced flow state that is. You forget everything and you become a hunter hunting down its prey, the bug. Well it happened to me here and there and although I fixed it every time, the uneasiness of deploying to production never left me.
How feature flags can help
Essentially feature flags are a way to quickly roll back a feature in case something goes wrong. Everyone knows how long a redeployment takes and no one wants to wait 10-30 minutes to revert a production app to a previous state. That is why most production environments have rollback scripts that are faster than a normal deployment. But what if you could just turn off the feature that is causing the problem and start the app again? This is where feature flags come in. They allow you to quickly toggle a feature on and off without redeploying.
A/B testing with feature flags
Most bigger projects roll out features in a controlled manner. This is called A/B testing. You can use feature flags to control the visibility of a feature to a certain group of users. This way you can test the feature with a small group of users and see how they react to it. This is a great way to get feedback on a feature before rolling it out to everyone.
-70% Sale
You might have guessed it, feature flags are also great for toggling sales and discounts. You can easily turn on and off a winter sale without having to redeploy the website or add a cms entry. Quick and dirty.
Nextjs and feature flags
Nextjs added a feature flagging system in beta in the newest version. Here is the article in reference: Feature Flags. Although feature flags can be simply implemented with environment variables and if clauses in the code, libraries like launchdarkly and Nextjs' own feature flagging system make it easier to manage and control the visibility of features in your app.
Make sure to try them out in your next side project and see how they can make your life easier.