Laravel released Pennant, a first-party feature flag package, during the Laravel 10 release cycle. This package offers a lot of capabilities, but at its basic level, what is a feature flag useful for?
Stripped down to its essentials, a feature flag is a way to turn some feature on or off in a specific environment.
For example, maybe you're planning to roll out your product to a new country, and you want to allow users in that country to sign up, along with a customized flow for questions and options specific to their location.
Until the feature is fully ready to use, or maybe on a specific date that coincides with other marketing efforts, you do not want to show this new flow when people sign up. So there may be multiple weeks or even months when you're working on the code, but not quite ready to "turn it on" in production.
In the past, I might do manage this with a long-lived branch where this code is being worked on, and then I'd be very careful to only deploy that branch to a specific test environment to have others review it.
This can be very frustrating. You have to keep it up to date with everything going on in the rest of the project. And it just adds friction to the deployment process.
This is a perfect use case for a feature flag. You can have the flag enabled in your test environment, but disabled in production, allowing you to merge small chunks of code and even ship them, but without making the new flow visible to the public.
And when the big day comes to launch, it's a simple environment change to go live. No big merge, no big deploy, just a flip of a switch.
Of course, there are much fancier things that feature flags can offer, like A/B testing, enabling per user or role, and so on, but this basic use case is a great starting point.
Here to help,
Joel
P.S. Did you know we publish these tips in ebook form for easy offline reading?