Skip to content
Velloreth
Technology 4 min read

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

What a flag does

It decouples a deploy from a release.

TermMeaning
Deploythe code is in production
Releasethe 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

TypePurposeLifetime
Releasehide an unfinished featuredays to weeks
Permissiongrant accesspermanent
Experimentassign a variantweeks
Operationala kill switchpermanent
Configurationchange a valuepermanent

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.

For the related topics, see canary-deployments and blue-green-deployments. For the broader context, ci-cd-pipeline-basics and technical-debt-conversation.

Frequently asked questions

What is a feature flag?
It is a conditional in the code that decides whether a feature is active, evaluated at run time from a configuration rather than at build time. It decouples a deploy, which puts the code in production, from a release, which turns the feature on.
What are the types of feature flag?
A release flag hides an unfinished feature, a permission flag grants access to a user or a group, an experiment flag assigns a variant, an operational flag is a kill switch, and a configuration flag changes a value. A release flag is temporary and a permission flag is permanent.
Why are feature flags technical debt?
Because each flag is a branch in the code, and the branches multiply. A flag that is left in place after the feature is released is a branch that is never tested in the other state. The fix is an owner and an expiry date for every flag, and a review that removes the expired ones.
Should a flag be evaluated on the client or the server?
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. A flag that gates a paid feature must be on the server.
What is a kill switch?
An operational flag that disables a feature in production without a deploy. It is used when a feature is suspected of causing an incident, and it is the fastest way to stop the damage. It should be tested, because a kill switch that does not work is worse than none.
How do I test a feature flag?
Test both states, and test the transition. A flag that is only tested in the on state is a flag whose off state is broken. Add a test for the off state, and a test that the flag is read from the configuration rather than hardcoded.