← Building blocks

Ship dark, release gradually

Observability & operationsfundamental

Every deploy is a big-bang release and rollback means redeploying.

Say it like this

I separate deploy from release: the new code ships dark behind a flag, I turn it on for 1% then a cohort then everyone while watching the SLO, and if it misbehaves I flip it off in seconds without a deploy.

Basic solution

Gate new behaviour behind flags; turn on for a percentage or a cohort; kill switch without a deploy.

LaunchDarklyUnleashconfig service

Same build, two paths, cohort by stable hash

Every instance evaluates flags from an in-memory rule set refreshed from the flag service. A stable hash of the user id picks the cohort; the dashboard compares cohort metrics and can flip the flag off fleet-wide in under a minute.

How it works

  1. The code wraps the new behaviour in a check: if flags.enabled("ranked-feed", user) run the new path, else run the old one. Both paths ship in the same build, so deploying the code does not release the feature.
  2. A flag service holds the rules for each flag: off, on, a percentage, an allow-list of accounts, or a condition on attributes such as region or app version. A percentage rule uses a stable hash of the user id, so the same user lands in the same bucket on every request rather than flipping between paths.
  3. Each service pulls the full rule set at start-up and keeps it in memory, refreshing every 30 seconds or when the flag service pushes a change. Evaluating a flag is therefore a local hash and comparison, with no network call on the request path.
  4. Rollout proceeds in steps: internal users first, then 1% of traffic, then 10%, 50% and 100%. At each step the error rate and latency of users with the flag on (the treatment cohort) are compared with users who have it off (the control cohort) before moving on.
  5. The kill switch is setting the flag to off. Every instance picks that up on its next refresh, typically within a minute, and reverts to the old path with no build or deploy.
  6. Clean-up follows. Once the flag has been at 100% and stable for a release cycle, the old path and the flag check are deleted from the code; the flag service reports flags whose rules have not changed in 90 days so they do not pile up.

What flags give you that deploys cannot

  • A rollback measured in seconds, a rollout by user and by cohort rather than by server, and the ability to test with real production traffic before anyone outside the team sees the feature.

Worked example

News feed: switching from chronological to ranked

  • The ranked path adds a 60 ms ranking call and a feature fetch; the risk is latency and a silent quality regression.
  • Rollout plan: employees (200 users) for 2 days; 1% of users (500K of 50M DAU) for 3 days; 10%; 50%; 100%. Each cohort is a hash of user id mod 1000 compared with the percentage, so the same users stay in the cohort across sessions.
  • Metrics per cohort: feed p99 (control 180 ms, treatment 250 ms, within the 300 ms SLO), error ratio (both 0.02%), and the engagement metric the product cares about (sessions per day up 4% in treatment).
  • At 10%, 5M users: the ranking service sees 2K requests/s, enough to find a hot-key problem in the feature store that 1% never triggered. The flag is paused at 10%, not rolled back, while the fix ships; nobody outside the 10% is affected.
  • A bad deploy of the ranking service at 50% raises treatment error ratio to 2%. The flag is switched off from the dashboard; within 45 seconds all 50M users are back on the chronological path. The ranking deploy is then rolled back without pressure.
  • Flag evaluation cost: 20K feed reads/s × one in-memory hash and comparison, microseconds each; the flag refresh is one 50 KB fetch per instance every 30 seconds.

Variants and when each wins

Release flags (short-lived)

  • A flag that exists only to gate one rollout and is deleted afterwards. It wins for shipping a feature safely and is the main use; it must be removed once the flag reaches 100%.

Operational kill switches (long-lived)

  • A flag that turns off a non-critical feature under load, such as recommendations or image previews. It wins during incidents and is kept permanently, which means it must be exercised regularly so it still works.

Experiment flags (A/B)

  • A randomised flag with exposure logging and a statistics pipeline behind it. It wins when you need to measure the effect of a change; it needs stricter cohort assignment and analysis than a release flag.

Entitlement flags

  • Per-account features decided by the customer's plan. This is really configuration, and it wins when served from the account record rather than from the flag system.

Recommendation: a flag service with SDKs that cache locally, strict naming and owners, release flags deleted within one cycle, kill switches reviewed quarterly.

Failure modes

Flag debt

  • There are 400 flags, nobody knows which are safe to remove, and both code paths are maintained forever. It happens because removal was never part of the rollout. Give every flag an owner and an expiry date, publish a report of stale flags, and make removal part of the rollout's definition of done.

Flag service on the request path

  • An outage of the flag service takes down every feature at once. It happens because each request calls the service to evaluate the flag. Have the SDK evaluate from an in-memory copy with a default compiled into the code, so the service only supplies updates.

Inconsistent cohorts

  • A user sees the new feed on one page and the old feed on the next. It happens because the cohort is assigned at random on each request instead of by a stable hash of the user. Hash a stable key such as the user id, with the flag name mixed in, so the assignment is the same every time.

Flags interacting

  • A particular combination of two flags crashes. It happens because 2 to the power of N combinations exist and only the intended ones were tested. Keep release flags short-lived, test the combinations you intend to ship, and avoid nesting one flag check inside another.

Kill switch that does not kill

  • Flipping the flag off changes nothing, because the feature's data was already written or the client cached the old flag state. It happens because the off path was never designed. Decide explicitly what happens to in-flight work when the flag turns off, and give mobile clients a short TTL on their cached flag state.

Interviewer follow-ups

Answer out loud before you open each one.

How do feature flags differ from a canary deploy?

A canary rolls out a new build to a slice of instances, so the slice is by server. A flag rolls out a code path to a slice of users on every instance, so the slice is by user and can be turned on and off without touching deploys. They combine well: canary the build, then flag the feature.

How do you make sure a flag evaluation is fast and survives a flag-service outage?

The SDK loads the full rule set into memory at start, refreshes it in the background, and ships with a default value for every flag in code. Evaluation is a hash and comparison; the service being down only means rules stop updating.

What do you measure while ramping a flag?

The same SLO metrics split by cohort: error ratio and latency for users with the flag on versus off, plus the product metric the change is meant to move. A ramp step is held until the treatment cohort matches control on reliability.

When would you not use a flag?

For changes that cannot have two paths, such as a database schema change or a dependency upgrade; those need expand-then-contract migrations and canary builds instead. And for anything that becomes permanent configuration, which belongs in config, not a flag.

Connections

Pairs with
Deploy without downtime · Set SLOs and spend the error budget · Degrade instead of failing · Find services and config at runtime · Measure what users feel

The same parts on other clouds

The diagrams above name AWS services as one concrete example. Every part has a close equivalent elsewhere. In an interview, name the role first, such as “a managed Redis cache”, then the product you would pick.

AWSUsed here asGoogle CloudMicrosoft AzureOpen source and others
Amazon EC2 Auto ScalingFeed serviceCompute Engine managed instance groupsVirtual Machine Scale SetsKubernetes Deployment with a HorizontalPodAutoscaler, Nomad
Amazon CloudWatchCohort dashboardCloud Monitoring, Cloud LoggingAzure MonitorPrometheus and Grafana, Datadog