# Feature flag

> A switch in the code that turns a feature on or off without shipping a new version.

- Level: Intermediate
- Topics: Software
- URL: https://tidbit.legios.com.ar/feature-flag/
- In Spanish: [Feature flag](https://tidbit.legios.com.ar/es/feature-flag/)

A **feature flag** is an if-statement whose answer lives outside the code. The program asks "is `new_checkout` on for this user?" and a setting, usually stored in a config service or a database, says yes or no. Flip the setting and the app changes behavior right away, with no new build and no new deploy.

This separates two things that used to be the same moment: putting code on the servers and letting people use it. A team can merge an unfinished feature hidden behind a flag, turn it on first for employees, then for 1% of users, then 10%, watching errors and sales at each step. If something goes wrong, someone turns the flag off and the old behavior is back in seconds, without rolling back the whole release.

Flags also power A/B tests (half of users see version A, half see B), premium features that only paying customers get, and "kill switches" that shut off an expensive or broken part of a system during an incident. Services like LaunchDarkly, Unleash or Flagsmith manage them at scale.

The catch is that every flag doubles the number of paths through the code. Old flags that nobody removes pile up as technical debt, and a forgotten flag flipped by mistake can switch on code that has not run in years. Good teams give each flag an owner and an expiry date.

## An analogy

The light switches in a new house. The electrician wires every room on day one, but you decide which lights to turn on, and when, without calling the electrician back.

## Keep in mind

- Separates deploying code from releasing a feature to users.
- Enables gradual rollouts, A/B tests and instant kill switches.
- Turning a flag off is much faster than rolling back a release.
- Stale flags are technical debt: remove them once a feature is settled.

## Go deeper

- [Feature Toggles, by Pete Hodgson (martinfowler.com)](https://martinfowler.com/articles/feature-toggles.html)
- [Feature toggle on Wikipedia](https://en.wikipedia.org/wiki/Feature_toggle)

## Related terms

- [Database](https://tidbit.legios.com.ar/database/): An organized store of data that programs can search and update safely.
- [Deployment](https://tidbit.legios.com.ar/deployment/): Getting a new version of software from the team's computers to real users.
- [Server](https://tidbit.legios.com.ar/server/): A computer whose job is to answer requests from other computers, all day, every day.
- [Rollback](https://tidbit.legios.com.ar/rollback/): Going back to the last version that worked when a new one causes problems.
- [A/B testing](https://tidbit.legios.com.ar/ab-testing/): Showing two versions to two random groups and measuring which one works better.
- [Technical debt](https://tidbit.legios.com.ar/technical-debt/): The future cost of shortcuts taken in software today.
