Feature flag

Definition
A feature flag is a switch in the code that turns a feature on or off without a new deployment, letting a team control who sees it and when.

Why it matters

Without a flag, shipping a feature and releasing it to every user are the same event. A problem found afterwards can only be fixed by shipping again, often in a hurry. A flag separates the two. The code goes live quietly and is tried on a small group. It is switched on for everyone once it proves itself, or switched straight back off if something goes wrong. A risky release becomes a controlled one, and a rollback becomes a switch flip.

For people building with AI tools, where changes arrive fast, a flag also limits the harm from one that misbehaves.

How to apply it

  • Put any risky or customer-facing change behind a flag before it reaches production, not after a problem appears.
  • Release to internal accounts first, then a small percentage, and watch real numbers before widening.
  • Give every flag an owner and a removal date.
  • Remove the flag and the old code once the decision is final.

What it is

A feature flag is a condition wrapped around new behaviour: if the flag is on for this user, show the new version, otherwise show the old one. The flag's value lives in a settings screen or service, not in the code, so changing it takes seconds and needs no new release. It can be on for everyone, off for everyone, or on for chosen accounts or a percentage of users.

Common mistakes

  • Leaving flags in the code for months. Each one doubles the paths that need testing, and old flags become technical debt.
  • Treating a flag as a security control. Hiding a button is not the same as blocking access.
Worked example

Suppose a product team is about to release a new checkout to all 8,000 users. Instead of shipping it to everyone at once, the code goes live behind a flag that is off for everyone. The flag is switched on for the team's own accounts first, then for 5% of users. Problems in the new checkout show up in the first hour, and the flag is switched off in the settings without a new release.

The team fixes the bug, widens the rollout to 50%, and then to everyone. The flag and the old checkout code are removed a month later. The flags are managed in PostHog, which combines feature flags, experiments and product analytics in one stack.

Tools in the example

Some links are affiliate links: we may earn a commission at no cost to you. It never decides a ranking. How we work with partners

  1. Article

    Deployment

    The act of putting code live, which a flag separates from release.

  2. Article

    Staging environment

    The place to test before a flag reaches real users.

  3. Article

    A/B testing

    A flag that shows different versions to different groups.

  4. Article

    Edge case

    The kind of problem a staged rollout surfaces early.

Where it shows up

  • Writing copy that feels like conversation instead of marketing. How to sound like yourself.
    12 chapters