The Hook (The "Byte-Sized" Intro)
Long-lived feature branches are painful โ merge conflicts, stale code, big-bang integrations. Feature flags let you merge incomplete features into main behind a toggle. The code is deployed but not visible. When the feature is ready, flip the flag โ no deployment needed. Branch lifetime drops from weeks to hours.
๐ What is the Feature Flag Workflow?
A workflow where incomplete features are merged to main behind toggles (feature flags), enabling continuous integration without exposing unfinished work to users.
Conceptual Clarity
Feature flags vs feature branches:
| Approach | Integration | Risk | Branch Lifetime |
|---|---|---|---|
| Feature branch | At merge time | Big-bang merge conflicts | Days to weeks |
| Feature flag | Continuous to main | Small, incremental | Hours to 1 day |
Flag lifecycle:
| Phase | Flag State | Users See |
|---|---|---|
| Development | OFF | Nothing new |
| Internal testing | ON for team | Team only |
| Beta | ON for 10% | Beta users |
| GA rollout | ON for all | Everyone |
| Cleanup | Flag removed | Feature is permanent |
Real-Life Analogy
Feature flags are like a restaurant's "coming soon" menu item. The dish is prepared and tested in the kitchen (merged to main), but it's not on the public menu (flag is off) until the chef is confident.
Visual Architecture
Why It Matters
- Continuous integration: Merge to main daily, not after weeks.
- Risk reduction: Gradual rollout catches issues before 100% exposure.
- Instant rollback: Flip the flag off โ no revert, no deployment.
- Independent deploy & release: Deploy code anytime, release when ready.
Code
// โโโ Simple feature flag implementation โโโ
const FLAGS = {
newCheckout: false, // Toggle in config or service
darkMode: true,
};
function renderCheckout() {
if (FLAGS.newCheckout) {
return renderNewCheckout(); // New feature
}
return renderOldCheckout(); // Current feature
}
// โโโ Git workflow with feature flags โโโ
// 1. Create short-lived branch:
// git checkout -b feature/AUTH-42-new-login
//
// 2. Wrap new code in feature flag:
// if (flags.newLogin) { ... }
//
// 3. Merge to main (flag is OFF in production):
// git push โ PR โ squash merge
//
// 4. Gradual rollout via flag service:
// LaunchDarkly, Unleash, Flagsmith, or env vars
//
// 5. Cleanup: remove flag + old code after GA
// git checkout -b chore/remove-login-flagKey Takeaways
- Feature flags decouple deploy from release โ merge code, release later.
- Branch lifetime drops from weeks to hours โ fewer merge conflicts.
- Gradual rollout (10% โ 50% โ 100%) reduces risk.
- Always clean up old flags โ flag debt is real tech debt.
Interview Prep
-
Q: How do feature flags change your branching strategy? A: They enable trunk-based development โ short-lived branches merged to main daily, with features hidden behind flags. This eliminates long-lived feature branches and big-bang merges.
-
Q: What is the difference between deploying and releasing? A: Deploying means shipping code to production. Releasing means making it available to users. Feature flags let you deploy code without releasing it โ the flag controls user visibility.
-
Q: What is "flag debt" and how do you prevent it? A: Flag debt is old feature flags left in the codebase after the feature is fully released. They add complexity and branching logic. Prevent it by treating flag removal as part of the feature's completion โ not done until the flag is removed.