Black Friday: 30% off every plan through November 30. See the prices
SysDesignPrep.com
Study guide

Updated 27 October 2026

Feature flags and A/B testing

Feature flags for safe releases, how flag evaluation works at scale, gradual rollouts and kill switches, A/B test design with consistent assignment, exposure logging, metrics and guardrails, network effects, and flag hygiene.

Reading is half of it. Now try it in an interview.An AI interviewer asks you to design an A/B Testing Platform, out loud or typed, and scores the answer for your level. Or watch a sample interview first, free with no sign-up to start.
Start an AI mock

Try it yourself, in a playground:Canary deploymentsA/B test peekingMulti-armed banditsFeature flag rollouts

Large products change dozens of times a day without breaking for everyone, because changes ship behind feature flags and are measured with experiments. Both come up in interviews as part of "how would you roll this out?" and "how would you know it worked?", and occasionally as a full design question: see Design an A/B Testing Platform.

Feature flags

A feature flag is a runtime switch that decides which code path runs, without a deploy:

  • Release flags: ship code dark, then turn it on gradually.
  • Kill switches: turn off a misbehaving feature in seconds.
  • Operational flags: switch to a fallback, change a limit, shed a non-critical feature under load.
  • Permission and entitlement flags: features for certain plans, tenants or beta users.
  • Experiment flags: assign users to variants of an A/B test.

Evaluating flags at scale

Flags are checked on almost every request, so evaluation must be local and fast:

  • A flag service stores rules (targeting by user, tenant, region, app version, percentage).
  • SDKs in each service download the full rule set and evaluate locally in microseconds; they receive updates by streaming or polling (seconds).
  • If the flag service is unreachable, SDKs keep the last known rules, with safe defaults for brand-new flags. A flag outage must never take down the product.
  • Every change to a flag is audited (who, when, what), because flags are production changes.

Gradual rollouts

Roll out by percentage with consistent hashing of the user id (hash(flag, user) mod 100 < percentage), so each user stays in the same group as the percentage grows, and different flags are independent. A typical rollout: internal users, 1 %, 5 %, 25 %, 50 %, 100 %, watching error rates and latency at each step, with automatic rollback if guardrails break. See observability, operations and rollouts.

A/B testing

An experiment compares variants on randomly assigned users to measure the effect of a change.

Assignment: deterministic and sticky, by hashing the user (or device, for logged-out traffic) with the experiment id. Users must not flip between variants.

Exposure logging: record when a user actually saw the variant, not just that they were assigned, and analyse only exposed users. Otherwise effects get diluted by users who never reached the feature.

Metrics:

  • A primary metric chosen before the test (conversion, retention, sessions per user).
  • Guardrail metrics that must not get worse (latency, errors, unsubscribes, revenue).
  • Per-metric statistics with confidence intervals, computed in the analytics warehouse from events joined to assignments. See OLTP versus OLAP.

Sample size and duration: decide them up front from the minimum effect worth detecting, run for whole weeks (behaviour differs by weekday), and do not stop early when the result looks good ("peeking" inflates false positives unless you use sequential testing methods).

When users are not independent

Standard A/B tests assume one user’s variant does not affect another’s outcome. That breaks in:

  • Marketplaces: a new ranking for some riders changes which drivers are available to the others. See Design DoorDash.
  • Social products: a feature for some users changes what their friends see.
  • Shared resources: a change that uses more cache or capacity slows everyone.

Use switchback tests (alternate the whole region between variants by time window) or cluster randomisation (assign whole cities, or groups of connected users), at the cost of fewer independent units and more noise.

Running many experiments at once

Large platforms run hundreds of concurrent experiments. Layers keep experiments that could interfere (two ranking changes) mutually exclusive, while experiments in different layers (ranking and button colour) overlap freely. Holdout groups that see none of the quarter’s changes measure their combined effect.

Flag hygiene

Flags are technical debt: every flag doubles the paths through the code. Give every flag an owner and an expiry date, remove release flags once fully rolled out, and alert on flags that have been at 100 % for weeks. Stale flags have caused real outages when someone flipped one years later.

In the interview

For any risky change, say: behind a flag, rolled out by percentage with consistent assignment, guarded by error and latency metrics with automatic rollback, and (if it is a product change) measured by an A/B test with a primary metric and guardrails, using switchback or cluster randomisation if users interact.

Checklist

  • Local flag evaluation with streamed updates and safe defaults.
  • Audited flag changes and kill switches for risky features.
  • Percentage rollouts with consistent hashing and automatic rollback.
  • Sticky assignment, exposure logging, primary and guardrail metrics.
  • Sample size decided up front; whole weeks; no peeking.
  • Switchback or cluster designs where users interact.
  • Owners and expiry dates for every flag.

Questions people ask

What is a feature flag?

A feature flag is a runtime switch that decides which code path runs, without a deploy. Teams use flags to ship code dark and turn it on gradually, as kill switches that turn off a misbehaving feature in seconds, to switch to a fallback or shed a non-critical feature under load, to gate features by plan, tenant or beta group, and to assign users to A/B test variants. Every flag change is a production change, so it is audited: who, when and what.

What is the difference between a feature flag and an A/B test?

A feature flag controls which code path runs for whom, while an A/B test uses a flag to compare variants on randomly assigned users and measure the effect of a change. Put simply, the flag answers "how would you roll this out?" and the experiment answers "how would you know it worked?". An A/B test adds sticky assignment by hashing the user with the experiment id, exposure logging, a primary metric chosen in advance and guardrail metrics that must not get worse.

How do feature flags work at scale?

Feature flags are evaluated locally inside each service, because they are checked on almost every request. A flag service stores the targeting rules (by user, tenant, region, app version or percentage), and SDKs download the full rule set, evaluate it in microseconds and receive updates by streaming or polling within seconds. If the flag service is unreachable, SDKs keep the last known rules, with safe defaults for brand-new flags, so a flag outage never takes down the product.

How do you do a gradual percentage rollout?

Roll out by percentage using a consistent hash of the user id, including a user when hash(flag, user) mod 100 is below the percentage. Each user then stays in the same group as the percentage grows, and different flags stay independent. A typical rollout goes to internal users, then 1 %, 5 %, 25 %, 50 % and 100 %, watching error rates and latency at each step, with automatic rollback if guardrails break.

How long should an A/B test run?

Decide the sample size and duration before the test starts, from the minimum effect worth detecting, and run it for whole weeks because behaviour differs by weekday. Do not stop early when the result looks good: this "peeking" inflates false positives unless sequential testing methods are used. Analyse only users who were actually exposed to the variant, not everyone assigned, or the effect is diluted by users who never reached the feature.

How do you A/B test when users affect each other?

Use switchback tests, which alternate a whole region between variants by time window, or cluster randomisation, which assigns whole cities or groups of connected users to one variant. Standard A/B tests assume one user's variant does not affect another's outcome, which breaks in marketplaces, social products and shared resources: a new ranking for some riders changes which drivers are available to the others. The cost of these designs is fewer independent units and more noise.