# What is a feature flag?

Source: https://appfig.com/glossary/feature-flag

A feature flag is a switch in your code that turns a feature on or off for some or all users without releasing a new version.

A feature flag (also called a feature toggle) is a condition in your code that decides at run time whether a feature is on. The decision comes from a service outside the app, so you can ship the code switched off, turn it on for a few users, and turn it off again if something goes wrong, all without a new release.

```kotlin
if (AppFig.isFeatureEnabled("new_checkout")) {
    showNewCheckout()
} else {
    showOldCheckout()
}
```

## The common kinds of flag

Pete Hodgson's widely used [taxonomy of feature toggles](https://martinfowler.com/articles/feature-toggles.html) sorts them by how long they live and who changes them:

- **Release flags** hide unfinished work so it can be merged and shipped before it is ready. They should be short-lived.
- **Experiment flags** split users into groups for an A/B test.
- **Ops flags** are kill switches: a way to turn off a feature that is causing trouble in production.
- **Permission flags** turn a feature on for particular users, such as paying customers or beta testers. These can live for years.

## Why flags matter more on mobile

On the web a bad release can be rolled back in minutes. In a mobile app the bad version stays on users' phones until a fix passes store review and each user installs it. A flag is often the only way to switch something off today. It is also the usual way to release gradually: ship the code to everyone, then turn the feature on for 5% of users and watch the crash and revenue numbers before going further.

## Targeting: who gets the feature

A flag rarely stays a plain on/off for everyone. Typical rules are a percentage of users, a country, a platform or app version, a user property such as subscription tier, or behavior: what the user has done in the app. Behavior is the hardest to target in tools that decide on a server, because the server has to learn about the behavior first.

AppFig decides on the device, so a rule can refer to events the app has just logged, for example "completed 10 levels in the last 7 days". The first rule that matches wins; if none matches, the flag has no value and your code falls back to its default. The details are in [Core concepts](/docs/concepts) and the [rule schema](/docs/rule-schema).

## The cost of flags

Every flag is a branch in the code, and both sides have to keep working. Flags that are never removed pile up, and a stale flag that someone flips by mistake can switch on code nobody has tested in months. Good practice is simple: give each flag an owner, remove release and experiment flags once the decision is made, and keep long-lived flags few and documented.

## FAQ

### What is the difference between a feature flag and remote config?

A feature flag is an on/off switch; [remote config](/glossary/remote-config) also carries numbers, text and JSON. In practice the same tool does both, and a flag is a config value that happens to be "on" or "off".

### Do feature flags slow an app down?

It depends on where the flag is evaluated. If each check is a network call, yes. If the SDK holds the rules or values on the device, a check is a local lookup. AppFig checks rules on the device with no network call.

### Can I use feature flags for A/B testing?

Yes. An experiment is a flag whose value depends on which group the user was assigned to, plus a way to measure the outcome. In AppFig an experiment keeps each user in the same variant and reports results from your own Google Analytics; see [Experiments](/docs/experiments).

### Do feature flags work offline?

Only if the SDK caches them. AppFig keeps its rules on the device and keeps evaluating them without a connection.
