Lesson Completion
Back to course

Feature Flag Workflow

Intermediate
8 minutesโ˜…4.8Git

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:

ApproachIntegrationRiskBranch Lifetime
Feature branchAt merge timeBig-bang merge conflictsDays to weeks
Feature flagContinuous to mainSmall, incrementalHours to 1 day

Flag lifecycle:

PhaseFlag StateUsers See
DevelopmentOFFNothing new
Internal testingON for teamTeam only
BetaON for 10%Beta users
GA rolloutON for allEveryone
CleanupFlag removedFeature 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

flowchart LR DEV["๐Ÿ”ง Develop"] --> MERGE["๐Ÿ”€ Merge to Main<br/>Flag OFF"] MERGE --> TEST["๐Ÿงช Internal Test<br/>Flag ON for team"] TEST --> BETA["๐Ÿ“Š Beta Rollout<br/>Flag ON 10%"] BETA --> GA["๐Ÿš€ GA<br/>Flag ON 100%"] GA --> CLEANUP["๐Ÿงน Remove Flag"] style MERGE fill:#0f3460,stroke:#53d8fb,color:#53d8fb style GA fill:#1b2d1b,stroke:#53d8fb,color:#53d8fb

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

javascript
// โ”€โ”€โ”€ 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-flag

Key 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.

Topics Covered

WorkflowsFeature Flags

Tags

#git#feature-flags#trunk-based#workflow

Last Updated

2026-02-13