System design interview: design a feature flag service

A feature flag service lets teams turn features on or off, or roll them out to a percentage of users, without deploying code. The interview hinges on one insight: flags are read millions of times a second but changed a few times a day, so services should evaluate flags locally from a cached copy of the rules and receive changes by streaming, rather than calling a central service for every check.

By Published 8 min read

1. Clarify the requirements

Products in this space include LaunchDarkly, Unleash, Flagsmith and many in-house systems. The design below is generic; ask whether the interviewer wants server-side flags only or also flags in mobile and web clients, because client flags change the security model.

  • Functional: create boolean and multi-value flags; target by user attributes (country, plan, employee); roll out by percentage; kill switch that turns a feature off everywhere; experiments with variants; audit log of every change; per-environment settings (dev, staging, prod).
  • Non-functional: evaluation adds microseconds, not a network round trip; a change reaches all servers within seconds; the system keeps working if the flag service is unavailable; every change is attributable and reversible.
  • Out of scope unless asked: the statistics of experiment analysis, a full permissions system for the admin UI.

2. Estimate the scale

Back-of-envelope estimate for a large company's flag platform (assumed figures)
QuantityAssumptionResult
Flags2,000 active flags, about 2 KB of rules eachabout 4 MB of configuration in total per environment
Server instances10,000 running services with an SDK10,000 streaming connections to keep open
Evaluationsa few flag checks per request across all servicesmillions a second, all inside application memory
Client devices50 million devices fetching flags about 5 times a day250 million fetches a day, about 2,900 a second
Changesa few hundred flag edits a daytiny write load; correctness and audit matter more than throughput
Back-of-envelope estimate for a large company's flag platform (assumed figures). Scroll sideways on a small screen.

Four megabytes of rules fits comfortably in every process. If evaluations went through a central service, it would need to answer millions of calls a second with single-digit millisecond latency; local evaluation removes that problem entirely.

3. Define the API

PUT  /v1/envs/{env}/flags/{key}   { on, variants, rules[], rollout: { percent, variant }, version }   (admin, audited)
GET  /v1/envs/{env}/config        -> 200 { version, flags[] }          (server SDK bootstrap, ETag)
GET  /v1/envs/{env}/stream        -> server-sent events: { version, changedFlags[] }
POST /v1/client/evaluate          { userContext } -> 200 { flags: { key: value } }   (mobile and web, client key)
Admin writes, SDK config sync, and a client-facing evaluation endpoint.

Server SDKs receive the full rules because they run in trusted environments. Browsers and mobile apps receive only the evaluated values for their user, because shipping all rules to a client would leak unreleased feature names and targeting criteria.

4. Sketch the data model

Configuration and history
EntityStoreFields
FlagRelational databasekey, environment, on/off, variants, default variant, owner team, created_at, expires_at reminder
RulePart of the flag documentordered list: attribute, operator, values, variant to serve
RolloutPart of the flag documentpercent, variant, optional bucketing attribute (user, account, device)
Config snapshotObject storage and CDN, per environment and versionAll flags of an environment as one JSON file; SDKs bootstrap from it
Audit entryAppend-only tablewho, when, flag, before, after, reason
Configuration and history. Scroll sideways on a small screen.

5. Evaluate locally, bucket deterministically

Evaluation is a pure function of the flag's rules and the user's attributes, so it runs inside the SDK. Rules are checked in order; the first match wins; if none matches, the percentage rollout decides. The bucket must be stable for a user, and independent between flags, so a user in 10% of one rollout is not automatically in 10% of every other.

import hashlib

def bucket(flag_key: str, user_id: str) -> int:
    """Stable bucket 0..9999 for this user and flag."""
    digest = hashlib.sha256(f"{flag_key}:{user_id}".encode()).digest()
    return int.from_bytes(digest[:8], "big") % 10_000

def is_enabled(flag: dict, user: dict) -> bool:
    if not flag["on"]:
        return False
    for rule in flag["rules"]:                      # first matching rule wins
        if user.get(rule["attribute"]) in rule["values"]:
            return rule["serve"]
    return bucket(flag["key"], user["id"]) < flag["rollout_percent"] * 100
Stable percentage bucketing and rule evaluation. Run on 200,000 synthetic users: the 20% group contains the 10% group.
  • Monotonic rollouts. Because the bucket never changes, raising a rollout from 10% to 20% keeps the first group and adds new users, so nobody flips back and forth.
  • Salt per flag. Including the flag key in the hash makes buckets independent across flags. Experiments that must not overlap can share a salt and take disjoint bucket ranges instead.
  • Bucket by the right unit. For a team product, bucket by account ID so everyone in one company sees the same thing.
  • Kill switch. The on field short-circuits everything, which is what you flip during an incident.

6. The architecture

  1. Control
    • Admin UI
    • Admin API (validation, approvals)
    • Flags DB + audit log
  2. Distribution
    • Snapshot publisher
    • Object storage + CDN
    • Streaming service (SSE)
  3. Server apps
    • SDK with in-memory rules
    • Local disk cache of last config
  4. Clients
    • Edge evaluation service
    • Mobile and web SDKs (values only)
  5. Feedback
    • Evaluation events (sampled)
    • Experiment analysis
    • Stale flag reports
Control plane, distribution and evaluation of feature flags. Engineers change flags in an admin UI backed by an admin API, which validates the change, writes it to a relational database with an audit entry and increments the environment's version. A publisher writes a full config snapshot to object storage behind a CDN and sends a change event to a streaming service. Server SDKs inside each application bootstrap from the snapshot, keep the rules in memory, hold a streaming connection for changes, and poll as a fallback. Mobile and web clients call an edge evaluation service that evaluates flags for the user and returns only values. SDKs send sampled evaluation counts to an events pipeline for usage tracking and experiment analysis.
  1. ChangeAn engineer raises a rollout from 5% to 25%. The admin API checks permissions, records the old and new values in the audit log, and bumps the environment version.
  2. PublishThe publisher writes a new snapshot and pushes a small change event to the streaming fleet.
  3. ApplyEach SDK receives the event, fetches the changed flags (or the snapshot), validates the version is newer, and swaps the rules atomically in memory.
  4. ConfirmSDKs report the version they run, so the UI can show when every service has the change.

7. Make it safe to depend on

  • Defaults in code. Every flag check names a default, used if the SDK has no rules yet. Choose the safe default (usually the old behavior).
  • Last known good. SDKs keep the last config on local disk and load it at startup if the service is unreachable.
  • Streaming plus polling. Streams can silently stall; a poll every minute or so with the ETag catches missed updates cheaply. Servers converge on the newest version within seconds, an eventual consistency choice of the kind discussed in consistency and CAP.
  • Guarded changes. Production changes to flags marked critical can require a second approver, and very large percentage jumps can trigger a warning.
  • Cleanup. Old flags are technical debt. Track when each flag was last changed and last evaluated, and nag owners to remove fully rolled-out ones.

8. What breaks, and what you do about it

Failure modes worth naming
FailureEffectMitigation
Flag service downNo new changes reach appsApps keep evaluating cached rules; only changes are delayed
Bad rule pushed (e.g. 100% instead of 10%)Feature exposed to everyoneAudit trail plus one-click revert to the previous version; staged rollout of risky flags
Reconnect storm after a streaming outage10,000 SDKs reconnect at onceJittered reconnect delays, CDN-served snapshots for the bootstrap
Client key extracted from an appSomeone reads flag valuesClient endpoint returns only values for that user; no rules or unreleased names
Inconsistent versions during a changeTwo servers briefly disagreeAcceptable for seconds; for coupled changes, use one flag rather than two
Failure modes worth naming. Scroll sideways on a small screen.

9. Trade-offs to discuss

  • Local or remote evaluation. Local is fast and resilient but needs SDKs in every language and ships rules to every service; remote is simpler to build but adds latency and a hard dependency.
  • Streaming or polling only. Streaming updates within seconds at the cost of long-lived connections; polling every 30 to 60 seconds is simpler and often good enough.
  • Flags as config or as code. Managing flags in a UI is quick for product teams; storing them in the repository gives review and history through the normal code process.
  • Build or buy. A homegrown system fits exactly but needs SDKs, a UI and audit; a vendor brings all of that with a different cost and data-sharing profile.

Flags are how ranking and model changes are tested in other designs, for example the experiments in a recommendation system, and how risky behavior in an email service, such as a new spam filter, is turned on gradually.

10. How to talk through it in the interview

Fictional example

The "what if your service goes down?" follow-up
Interviewer
Your flag service has an outage. What happens to the hundred services that use it?
Candidate
Nothing visible. Each service evaluates flags from rules in its own memory, so checks keep working. New flag changes are delayed until the service is back. A service that restarts during the outage loads the last config from its local disk or from the CDN snapshot, and if even that fails it uses the defaults written in code.
Interviewer
And a user who was in the 10% rollout yesterday?
Candidate
Still in it, because the bucket is a hash of the flag key and the user ID, not something stored by the service.
  • Lead with local evaluation and justify it with the evaluation rate.
  • Write the bucketing function; it answers consistency questions on its own.
  • Mention audit and revert; operators care about who changed what more than about throughput.

Practicing this design with Natively

Feature flags look like a small prompt, so interviewers push on edge cases: outages, client security, consistent bucketing. Rehearse them in a mock call. Natively records a transcript of the conversation on your computer and, at a keypress, offers talking points for the current question, for instance defaults in code or a reconnect storm. You can ask it to draw the control plane and SDK flow to compare with your sketch. Afterwards, check the notes for the moment you first mentioned local evaluation; earlier is better.

Questions people ask

How do you design a feature flag system?

Store flags and targeting rules in a database behind an audited admin API, publish each environment's rules as a snapshot and as change events, and have SDKs inside every service keep the rules in memory and evaluate flags locally. Mobile and web clients call an evaluation endpoint that returns only their values.

How does a percentage rollout keep the same users enabled?

The SDK hashes the flag key together with the user ID into a fixed bucket, for example 0 to 9999, and enables the flag when the bucket is below the rollout percentage. The bucket never changes, so raising the percentage only adds users, and including the flag key keeps buckets independent across flags.

What happens if the feature flag service goes down?

In a good design, nothing visible. Services keep evaluating the rules they hold in memory, restarts load the last config from local disk or a CDN snapshot, and code defaults cover the rare case where neither exists. Only new flag changes are delayed until the service recovers.

Should mobile apps download all feature flag rules?

No. Rules can reveal unreleased features and targeting criteria, and anything shipped to a device can be read. Client apps send their user context to an evaluation endpoint and receive only the resulting values, while server SDKs in trusted environments get full rules.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP