Reliability and security · L1Feature flags and entitlements

Feature flags and entitlements

Use flags to release safely and to run experiments, keep paid-plan rules apart, and remove every flag you no longer need.

L1 Must-knowReliability and security17 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 22 Oct 2026 · How we check content
Section 1 of 8

What broke

On 1 August 2012, Knight Capital, a large US trading firm, sent millions of unwanted orders in about 45 minutes. It lost more than $460 million. The U.S. Securities and Exchange Commission (SEC) later described what happened. 1

Knight was adding new code to SMARS, its order router, for a new New York Stock Exchange program. The new code was meant to replace old code for a feature called "Power Peg". Knight had stopped using Power Peg in 2003, but the code was still there and could still be called. 1

The new code also reused a flag that used to turn on Power Peg. The plan was simple: delete Power Peg, so that the flag would now turn on the new code. 1

From 27 July, Knight deployed the new code to its servers in stages. A technician did not copy it to one of the eight servers. No second technician reviewed the deploy, and no written procedure required a review. 1

On 1 August, orders arrived with the reused flag set. Seven servers ran the new code correctly. The eighth server ran Power Peg. Power Peg's counter of filled shares had been moved in 2005, and the old code was never tested again. So it sent new orders again and again without checking how many shares were already filled. 1

For 212 incoming orders, the system sent millions of orders. That gave 4 million executions in 154 stocks in about 45 minutes. 1

Section 2 of 8

The idea in simple words

A feature flag is an if statement whose answer comes from config, not from code. You can change the answer while the program runs, for some users or for all, without a new deploy.

Flags let you separate two things: deploying code and releasing a feature. You deploy the code switched off. Later, you turn it on for 1% of users, then more.

Pete Hodgson names four kinds of flags, and they live for very different lengths of time. 2

  • Release flags hide new or unfinished code. They should usually not stay "much longer than a week or two."
  • Experiment flags split users for an A/B test. They must stay stable long enough to give a clear result.
  • Ops flags let operators switch off a feature, for example under heavy load. Most are short-lived, but some stay as long-lived kill switches.
  • Permissioning flags turn features on for some users, such as paying customers. They can live for years.

The key idea. Every flag is a branch you must test and a switch that can break production. Give each one an owner, a reason and an end date, and delete it when its job is done.

Section 3 of 8

How it works

Step through one flag check for one user. Use Next and Back, or the ← and → keys.

One flag check for one user: context, rules, hash bucket, variant, cacheRequest Context Rules Hash bucket Variant Cached is new-checkout on?default: off user u-831 · plan procountry IN 1. staff list → no match2. rollout: 10% of users hash(flag + u-831) → 77 is at or below 10 ✓ variant: onreason: 10% split same answer next timerules kept in memory SeniorPath
  1. A request for user u-831 reaches the checkout code. The code asks one question: is the flag new-checkout on? It also passes a default, off, for when anything goes wrong.
  2. The code builds the evaluation context: the user ID, the plan and the country. The plan is here for other checks. This release flag does not use it.
  3. The flag has two rules, checked in order. Rule 1 turns it on for staff. User u-831 is not staff. Rule 2 turns it on for 10% of users.
  4. To pick the 10%, the tool hashes the flag name with the user ID. This user gets the number 7. Because 7 is at or below 10, the user is in the rollout. The same user always gets 7 for this flag.
  5. The answer is the variant on, with a reason that says why. Logging the variant and reason helps you debug odd behaviour later.
  6. In this example, the SDK keeps the flag rules in memory, so the next check needs no network call. When someone changes the rollout to 20%, the new rules reach the SDK, and user u-831 stays in.
Step 1 of 6

Context, rules and variants

Your code asks a question like "is new-checkout on for this request?". It passes an evaluation context: data about the request, such as the user ID. 5 You can add your own fields, such as the plan. 4 The flag's rules look at that context. OpenFeature calls this targeting: rules, user overrides or a percentage split. The answer is a variant, such as on, off or blue. 5

Keep the check in one place. Hodgson suggests a toggle router that makes the decision, so the rest of your code does not know how the decision is made. 2

Percentage rollouts and stable buckets

A 10% rollout must not flip a user between on and off on each request. So tools hash a user field instead of using a random number. Unleash uses MurmurHash on the user ID and a group ID to get a number from 0 to 100. By default the group ID is the flag name, so each flag splits users in its own way. Users whose number is at or below the rollout percentage get the feature. 3

The same input always gives the same number. 3 So raising 10% to 20% keeps the first 10% and adds more users. If there is no user ID or session ID, Unleash falls back to a random number, and the result is not stable. 3

Server or client evaluation

On a server, one process checks flags for many users, each with their own context. In a browser or phone app there is one user. The app usually fetches all its flag results at once and caches them. When the context changes, for example after login, the cached results are stale and must be fetched again. 5

Two habits follow from this. First, never trust a flag result that a client sends you for anything that matters, like access to a paid feature. Check it again on the server. Second, decide one flag per request, early, and pass the result down. Otherwise one request can see the flag as on in one service and off in another.

When the flag system fails

Your flag service can be slow or down. OpenFeature says a flag check must never throw an error, and must return the default value you supplied when something goes wrong. 6 So choose defaults with care. For a new feature, the safe default is usually off.

Entitlements are not release flags

An entitlement is what a customer's plan allows: "Pro can export to PDF", "Free gets 3 projects". It looks like a permissioning flag. Hodgson even uses paid features as an example of one, and says to manage each kind of flag differently. 2 We go one step further: treat entitlements as their own system.

This is our advice, not Hodgson's, for three reasons. Entitlements come from billing data, not from engineers. They last as long as the plan, so the "delete old flags" rule does not apply. And a wrong value can give away paid features or block a paying customer. Read the plan from your billing or account data, behind one function like canUse(account, "pdf-export"). You can still put a release flag around a new paid feature while you build it. The multi-tenancy lesson covers per-customer limits.

Flags are config changes, and they cost you

Turning a flag on for everyone changes production in seconds. Treat flag changes like config: review them, roll them out in steps and watch the metrics. The safe deploys lesson covers this. After its June 2025 outage, Google said changes to critical binaries must be behind flags that are off by default. 7

Each flag doubles the paths through one piece of code. Hodgson says you do not need to test every combination, because most flags do not interact. Test the setup you expect in production. Many teams also test with all flags on. 2

Old flags are flag debt. Hodgson describes teams that treat flags as inventory with a cost. Some add a removal task when they create a release flag. Some add "time bombs": tests that fail when a flag is past its end date. 2 The tech debt lesson shows how to track this kind of work.

A standard API: OpenFeature

OpenFeature is "an open specification that provides a vendor-agnostic, community-driven API for feature flagging". A provider is the "translation layer" between this API and your flag tool. 4 Your code calls one API, so you can change tools without rewriting every flag check.

Section 4 of 8

Trade-offs

Where the flag livesChange without deploy?RiskUse it when
Constant in codeNo A deploy is needed.Low. Easy to find and delete.A small team hides unfinished work on trunk.
Config file or env variableNo A restart or redeploy is needed.A typo can reach every server at once.Rare changes, like ops limits.
Flag service with SDKYes Seconds.A bad change is global in seconds. The service can fail.Gradual rollouts, kill switches and experiments.
Entitlement systemYes Driven by billing data.Wrong data gives away paid features or blocks customers.What each plan allows.

Simple rule: a release flag is temporary, so plan its removal on the day you create it. A rule that lasts as long as a plan is not a release flag.

Section 5 of 8

At work: how a senior uses this

  • Give each flag a clear name, an owner, a kind (release, experiment, ops or permissioning) and an end date.
  • Never reuse a flag name. Create a new flag, and delete the old flag and its old code.
  • Ask in review: "What does this do when the flag service is down?" The default must be safe.
  • Roll out by percentage with a stable user ID, and watch errors at each step before going wider.
  • When a release flag reaches 100%, open the cleanup pull request within a few weeks. Delete the flag and the old code path.
  • Keep a list of flags with their age. Bring old ones to the team's planning meeting.
  • Keep plan rules in an entitlement check, and check them on the server.
Section 6 of 8

With AI

What to ask the agent

"Find every feature flag in this repository. For each one, list the name, where it is checked, its default value, and whether one branch is now dead code."

"Remove the flag new-checkout, which is now on for 100% of users. Keep the 'on' path, delete the 'off' path and its tests, and remove the flag from config."

"Write tests for this function with the flag on and with it off. Also add one test with all flags on."

What to check yourself

  • The agent kept the correct branch when it removed a flag, and removed no other flag.
  • The default value used when the flag service is down is safe.
  • No paid feature depends only on a flag value sent from the client.
  • Rollouts use a stable user ID, not a random number per request.
  • The removed flag is also gone from the flag tool's config, so nobody can turn it on again by mistake.
Section 7 of 8

Check yourself

1. Which kind of flag should normally live for days or weeks, not years?

Show answer

A release flag. Release flags only hide unfinished or new code. Once the feature is fully on, you delete the flag and the old path.

2. You roll out a flag to 10% of users. Why hash the user ID instead of picking at random on each request?

Show answer

The same user gets the same answer every time, so the feature does not flicker on and off. A hash of the same input always gives the same number, so each user stays in or out of the rollout.

3. Your team wants to reuse an old, unused flag name for a new feature. What is the safest choice?

Show answer

Create a new flag, and delete the old flag and its old code first. At Knight Capital, a reused flag turned on old code that was still on one server. New flags and deleted dead code avoid this.

4. A customer moves from the Free plan to the Pro plan. Where should "Pro customers can export to PDF" live?

Show answer

In the entitlement system, which reads the customer's plan. What a plan allows is a business rule that lives as long as the plan. It should come from billing data, not a release flag.

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 7 sources and related lessons
  1. U.S. Securities and Exchange Commission, Order in the matter of Knight Capital Americas LLC, Release No. 34-70694 (16 October 2013) (opens in a new tab)
    The official account of the reused flag, the missed server and the losses on 1 August 2012 (paragraphs 1 and 12–17).
  2. Pete Hodgson, “Feature Toggles (aka Feature Flags)”, martinfowler.com (opens in a new tab)
    The four kinds of toggles, toggle routers, testing toggles and treating flags as inventory.
  3. Unleash documentation, “Stickiness” (opens in a new tab)
    How a real flag tool hashes a user ID into a number so each user gets a stable result.
  4. OpenFeature documentation, “Introduction” (opens in a new tab)
    What OpenFeature is, and what providers and evaluation context are.
  5. OpenFeature specification, “Glossary” (opens in a new tab)
    Server-side (dynamic context) and client-side (static context) flag evaluation, targeting and variants.
  6. OpenFeature specification, “Flag Evaluation API” (opens in a new tab)
    Why a flag check must never throw, and must return the default value on errors.
  7. Google Cloud, Service Health incident report for 12 June 2025 (official) (opens in a new tab)
    A new code path with no flag, and Google's rule afterwards that critical changes ship behind flags that are off by default.

Real incident: Knight Capital, 1 Aug 2012: Knight Capital: a missed server lost over $460 million in 45 minutes

Real incident: Google Cloud, 12 Jun 2025: Google Cloud outage: blank policy fields crashed API checks

Related: Safe deploys and config changes · CI/CD and trunk-based development · Testing strategy that scales · Managing technical debt · Multi-tenancy and noisy neighbours

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper