tezvyn:

Feature Flags: Ship Code Now, Release It Later

AI-drafted, machine-checkedSource: Wikipedia: Feature toggleintermediate

Feature flags are like light switches for your code, letting you turn features on or off in production without a new deployment. This enables canary releases and A/B tests. The main footgun is letting old flags accumulate, creating a maze of dead code.

WHY IT EXISTS The core problem feature flags solve is the tight coupling between deploying code and releasing a feature. Historically, shipping code meant users saw it immediately, making rollbacks risky and continuous integration difficult for large features. Flags were invented to break this link, allowing teams to deploy code safely without exposing it to users.

THE MENTAL MODEL A feature flag is a remote-controlled 'if' statement wrapped around a block of code. At runtime, your application checks a configuration to see if a feature should be enabled. This lets you ship code that is present but not active, and then release it on your own schedule. It's a powerful alternative to maintaining long-lived feature branches, which can be a nightmare to merge back into the main codebase.

HOW IT WORKS A simple implementation is a conditional block in the code that checks a value from a configuration file or, more commonly, a remote service. For example: if (flags.isNewCheckoutEnabledFor(user.id)) { showNewCheckout(); } else { showOldCheckout(); }. The flag service can then be configured to return 'true' for certain user IDs, for 10% of all users, or for everyone, all without changing the deployed code.

WHEN TO USE IT Use flags to decouple deployment from release. This is critical for continuous integration, where you merge code to the main branch frequently. It's also the foundation for progressive delivery techniques like canary releases (turn on for 1% of users, then 10%, etc.) and A/B testing (show 50% of users variant A, 50% variant B).

WHEN NOT TO USE IT Avoid using flags for permanent configuration, which is better handled by a standard config system. The biggest anti-pattern is letting flags become permanent fixtures in the code. Every flag should have a lifecycle plan for its removal to prevent the accumulation of technical debt, dead code, and untested execution paths.

ONE CANONICAL EXAMPLE A team builds a new dashboard, wrapping it in a flag that's 'off' by default. They merge and deploy their unfinished code daily without affecting users. Once complete, they enable the flag for internal employees. After testing, they enable it for 1% of users, then slowly ramp up to 100%, monitoring for errors. If a major bug appears, they can instantly turn the flag 'off' for everyone, reverting all users to the old dashboard without an emergency deployment.

Read the original → en.wikipedia.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.