Decoupling Deployment from Release
Trunk-Based Development creates an immediate practical problem: if everyone commits to main all day, how do you prevent half-finished features from breaking production?
The answer is Feature Flags (also called Feature Toggles). A feature flag is a conditional check in your code that controls whether a new feature is visible or active. It decouples deployment (putting code on the server) from release (making the feature available to users).
# A simple feature flag check
if feature_flags.is_enabled("new_checkout_flow", user=current_user):
# New, potentially incomplete code — safe to deploy, hidden from users
show_new_checkout()
else:
# Old, stable code — users see this until the flag is flipped
show_old_checkout()
This allows a developer to merge incomplete code into main safely. The code is deployed to production servers, but the flag is "off," so no user ever hits that code path. Once the feature is complete, tested, and ready, an operator flips the flag in a dashboard — no deployment required.
Feature flags enable several advanced patterns:
- Canary releases: Enable the flag for 1% of users first, monitor error rates, then gradually roll out to 100%.
- A/B testing: Show version A to half your users and version B to the other half, measure which performs better.
- Kill switches: If a new feature causes unexpected load on your database, flip the flag off instantly without rolling back a deployment.
- Beta programs: Enable a feature only for users who have opted into early access.
The cost of feature flags: They add complexity to your codebase. Every flag is a branch in your logic, which means more code paths to test. Flags that are never cleaned up after a feature is fully released become "flag debt" — dead code that confuses future developers. Mature teams treat flag cleanup as a first-class engineering task, tracked in their issue tracker like any other work.
A common interview question is: "How do you deploy code for a feature that isn't ready yet?" The expected answer involves feature flags, not "we wait until it's done." Interviewers are testing whether you understand the separation between deployment and release. Follow up by mentioning the operational benefits: instant rollback by flipping a flag is far faster and safer than reverting a deployment.