Feature Flags: Shipping Without Deploying
A flag decouples a deploy from a release. Learn the types, the lifecycle, the debt, and how to avoid a flag that never dies.
By Velloreth
What a flag does
It decouples a deploy from a release.
| Term | Meaning |
|---|---|
| Deploy | the code is in production |
| Release | the feature is active |
Without a flag, a deploy is a release.
With a flag, the code ships dark and the feature is turned on later.
The types
| Type | Purpose | Lifetime |
|---|---|---|
| Release | hide an unfinished feature | days to weeks |
| Permission | grant access | permanent |
| Experiment | assign a variant | weeks |
| Operational | a kill switch | permanent |
| Configuration | change a value | permanent |
A release flag is temporary. It is removed when the feature is fully released.
A permission flag is permanent. It is a part of the product.
Confusing the two is why a flag is never removed.
The lifecycle
1. Create the flag, off by default.
2. Ship the code with the flag off.
3. Turn it on for the team.
4. Turn it on for a percentage.
5. Turn it on for everyone.
6. Remove the flag and the dead branch.
The step that is skipped is step 6, and it is the one that matters.
The evaluation
Server-side:
if (flags.isEnabled('new-checkout', { userId })) {
return newCheckout(req);
}
return oldCheckout(req);
Client-side:
if (flags.isEnabled('new-header')) {
renderNewHeader();
}
The rule: a security decision must be on the server, because a client-side flag can be changed by the user.
A UI variation can be on the client, because the worst case is a wrong layout.
The targeting
A flag can be targeted:
- By user id
- By a group or a role
- By a percentage
- By a region
- By an attribute, such as a plan
A percentage rollout is the common pattern, and it must be sticky: the same user gets the same variant.
A sticky assignment is a hash of the user id and the flag name, so the assignment is stable.
The debt
Each flag is a branch in the code.
The branches multiply. Two flags are four states, and three flags are eight.
A flag that is left in place is a branch that is never tested in the other state.
The fix:
- An owner for every flag
- An expiry date
- A review that removes the expired ones
- A test for both states
A flag with no owner is a flag that nobody will remove.
The kill switch
An operational flag that disables a feature without a deploy.
It is the fastest way to stop the damage when a feature is suspected of causing an incident.
It must be tested. A kill switch that does not work is worse than none.
It must be reachable when the system is degraded, which means it must not depend on the system.
The platform
A flag service such as LaunchDarkly, Unleash, Flagsmith or a home-grown table.
The requirements:
- A fast evaluation, because it is on the request path
- A local cache, so a service outage does not break the application
- An audit log, so a change is traceable
- A default, so a missing flag does not break the code
A flag service that is on the request path is a dependency, and a dependency can fail.
The fix: a local cache with a fallback to the default.
Common mistakes
A flag that is never removed. Permanent debt.
No owner. Nobody removes it.
No expiry. It lives forever.
A client-side security flag. A bypass.
A flag with no default. A missing flag breaks the code.
A flag service on the request path with no cache. An outage.
A non-sticky percentage. A user sees both variants.
A flag tested in one state. The other state is broken.
A kill switch that is not tested. It does not work.
A flag for a permanent permission. It should be a role, not a flag.
A quotable summary
A feature flag is a run-time conditional that decouples a deploy from a release, and the types are a release flag, a permission flag, an experiment flag, an operational flag and a configuration flag. A release flag is temporary and must be removed, a security decision must be evaluated on the server, and every flag needs an owner and an expiry date, because a flag that is not removed is a branch that is never tested in the other state.
Related reading
For the related topics, see canary-deployments and blue-green-deployments. For the broader context, ci-cd-pipeline-basics and technical-debt-conversation.