Unlocking the Power of Feature Flags
Unlocking the Power of Feature Flags
So, you shipped a new feature. Congrats! Now the app’s acting weird. Do you nuke the whole release? Nah. Enter feature flags.
What Are Feature Flags?
Feature flags (aka feature toggles, aka “please don’t break prod”) let you flip features on or off without redeploying. It’s like hiding switches all over your codebase, so you can turn stuff on for your favorite users (or just yourself, let’s be honest) and turn it off when things inevitably go sideways.
Martin Fowler (yes, that Martin Fowler) calls feature flags “a powerful technique, allowing teams to modify system behavior without changing code.” (martinfowler.com) Translation: you can break things more safely.
Why Use Feature Flags?
Let’s say you want to test a new feature, but only on Dave’s machine because he’s the only one who reads the docs. Or maybe you want to roll out a change slowly, just in case it’s cursed. Feature flags let you:
- Deploy Safely: Ship code to prod, but keep the scary stuff hidden.
- A/B Testing: Show different features to different users and pretend you’re doing science.
- Instant Rollback: Flip a switch and pretend nothing ever happened.
- Continuous Delivery: Ship all the time, break things less (in theory).
Scott Hanselman says, “Feature flags let you separate deployment from release, giving you the power to experiment and react quickly.” (hanselman.com)
How Do Feature Flags Work?
It’s just a boolean, folks. On or off. Store it in your code, a database, or some SaaS. Your app checks the flag before running code. You can make it as complicated as you want — user-specific, time-based, or tied to the phase of the moon. But here’s a basic example in C#:
public async Task<IActionResult> Index()
{
if (await _featureManager.IsEnabledAsync("NewDashboard"))
{
return View("NewDashboard");
}
return View("OldDashboard");
}
If editing appsettings.json every time you want to flip a flag sounds like a bad time, you’re not wrong. A central flag management server with a proper web UI is the better move — no config files, no redeployments, just a switch you can flip from a browser. We’ll cover that later, or if you’re impatient: featureflags.app is free to try.
The Code Monkey’s Caution
With great power comes great spaghetti. Too many flags and your codebase becomes a haunted house. Label your flags, document them, and delete them when you’re done. (You won’t, but you should.)
Conclusion
Feature flags help you ship, experiment, and fix things before anyone notices. Use them wisely, and maybe you’ll survive your next release. Stay tuned for the next post, where we’ll talk about all the different ways you can overcomplicate feature flags.
Case closed. For now. Go get coffee.