Design an internal feature-flag and experimentation platform for a consumer company with:
Cover how flags are defined and targeted, how SDKs evaluate them (client and server), how changes propagate, how experiment exposures are logged and analysed, how you avoid flicker in the UI, and how you keep thousands of flags from turning into permanent technical debt.
The interviewer may ask you to compare building this with LaunchDarkly, Statsig, Optimizely, Unleash or GrowthBook, and to discuss what happens when the flag service is down.
Feature flags and experiments look like one product but have two different jobs:
A good design shares the evaluation engine between both, but treats exposure logging, metrics and governance as first-class concerns of the experimentation side. The most important architectural decision is where evaluation happens: locally in the SDK against a cached ruleset, not by calling a remote service on every check.
Two planes:
Plus an exposure and metrics pipeline for experiments.
{ "new-checkout": "treatment" }). Private rules never leave the server.For this brief, I would use bootstrap-from-SSR for web, remote evaluation at the edge for mobile, and local evaluation for services.
{
"key": "checkout.new-payment-sheet",
"type": "string",
"kind": "experiment",
"owner": "team-payments",
"createdAt": "2025-04-03",
"expiresAt": "2025-08-01",
"clientVisible": true,
"variations": [
{ "id": "control", "value": "legacy" },
{ "id": "treatment", "value": "sheet-v2" }
],
"environments": {
"production": {
"enabled": true,
"offVariation": "control",
"rules": [
{ "id": "r1", "description": "Employees always get treatment",
"conditions": [{ "attribute": "email", "op": "endsWith", "values": ["@acme.com"] }],
"serve": { "variation": "treatment" } },
{ "id": "r2", "description": "Excluded markets",
"conditions": [{ "attribute": "country", "op": "in", "values": ["DE", "FR"] }],
"serve": { "variation": "control" } }
],
"fallthrough": {
"rollout": {
"bucketBy": "userId",
"salt": "checkout.new-payment-sheet:exp-42",
"weights": { "control": 50000, "treatment": 50000 }
}
},
"prerequisites": [{ "flag": "checkout.platform-v2", "variation": "on" }]
}
},
"experiment": {
"id": "exp-42",
"layer": "checkout",
"trafficAllocation": 0.2,
"primaryMetric": "checkout_completed",
"guardrails": ["page_error_rate", "inp_p75"],
"hypothesis": "A sheet-based payment UI increases completion by 1%"
}
}
Evaluation order: flag off, serve offVariation; prerequisites; individual targets; rules in order; fallthrough
rollout. The order must be identical in every SDK, which is why a shared conformance test suite (a JSON file of
contexts and expected outputs) runs in every SDK's CI.
bucket = hash(salt + ":" + bucketByValue) mod 100000. Use a stable, fast non-cryptographic hash (MurmurHash3 or
FNV-1a are common) implemented identically on every platform. Key details:
{
"type": "exposure",
"flagKey": "checkout.new-payment-sheet",
"experimentId": "exp-42",
"variationId": "treatment",
"ruleId": "fallthrough",
"unitType": "userId",
"unitId": "u_8f2a",
"timestamp": "2025-06-02T10:15:03.120Z",
"sdk": "web@4.2.1",
"snapshotVersion": 18234
}
Only fallthrough rollouts inside an experiment produce analysable exposures; users matched by targeting rules
(employees) are excluded from analysis.
Application code should depend on OpenFeature, the CNCF vendor-neutral flag API, with a provider for our platform. That makes a later switch to or from a vendor a provider change, not a codebase rewrite.
import { OpenFeature } from '@openfeature/web-sdk';
await OpenFeature.setProviderAndWait(new AcmeProvider({ bootstrap: window.__FLAGS__, streaming: true }));
const client = OpenFeature.getClient();
const sheet = client.getStringValue('checkout.new-payment-sheet', 'legacy');
Our own SDK surface (what the provider wraps):
interface EvaluationContext {
targetingKey: string; // userId or deviceId
attributes: Record<string, string | number | boolean | string[]>;
}
interface EvaluationResult<T> {
value: T;
variationId: string;
reason: 'OFF' | 'TARGET_MATCH' | 'RULE_MATCH' | 'FALLTHROUGH' | 'PREREQUISITE_FAILED' | 'ERROR' | 'DEFAULT';
ruleId?: string;
experimentId?: string;
}
interface FlagClient {
evaluate<T>(key: string, defaultValue: T, ctx?: EvaluationContext): EvaluationResult<T>;
onChange(key: string, cb: (r: EvaluationResult<unknown>) => void): () => void;
trackExposure(key: string): void; // explicit, for lazy exposure
flush(): Promise<void>;
}
function PaymentStep() {
const { value, track } = useFlag('checkout.new-payment-sheet', 'legacy', { exposure: 'manual' });
useEffect(() => { track(); }, [track]); // log only when this step actually renders
return value === 'sheet-v2' ? <PaymentSheet /> : <LegacyPayment />;
}
exposure: 'manual' matters: logging exposure when the flag is merely evaluated (for example, during route
prefetching) dilutes the experiment with users who never saw the change.
acme-flags create checkout.new-payment-sheet --kind experiment --owner team-payments --expires 2025-08-01
acme-flags codegen --out src/flags.generated.ts # typed keys and variation values
acme-flags stale --repo . # flags fully rolled out for 30+ days, still referenced in code
Codegen gives typed flag keys so a typo is a compile error. A CI check fails if code references a flag that does not exist in the platform, and a weekly job opens clean-up PRs for flags that have been at 100% for 30 days.
localStorage for browsers) and, failing that, uses in-code defaults. Defaults must therefore be
the safe option, typically "old behaviour".Flicker (showing control, then swapping to treatment) both hurts UX and biases experiments. Prevent it by evaluating on the server and bootstrapping the client with the same values, or, for static pages, evaluating at the edge (middleware) and rewriting to a pre-rendered variant. Never block first paint on a client-side network call to the flag service. For live updates in the browser, decide per flag whether to apply immediately (kill switch) or on next navigation (UI experiment, to avoid layout jumps mid-task).
| Option | Notes |
|---|---|
| LaunchDarkly | Market leader for release management; mature SDKs, streaming, approvals, strong governance. Experimentation is an add-on. Cost scales with seats and MAU/contexts and becomes significant at 20M MAU. |
| Statsig, Optimizely, Eppo | Experimentation-first; stronger stats engines (CUPED, sequential testing). Eppo and Statsig support warehouse-native analysis. |
| Unleash | Open source, self-hostable, good for release flags; experimentation analysis is not its focus. |
| GrowthBook | Open source, warehouse-native experimentation plus flags; good when data already lives in Snowflake/BigQuery. |
| Flagsmith, Flipt, PostHog | Open-source or open-core alternatives with different strengths. |
| Build | Full control and no per-MAU cost, but you own SDKs on 5 platforms, a stats engine, streaming infra and an audit-ready UI. That is a team of 5–8 engineers indefinitely. |
Recommendation: standardise the application API on OpenFeature first. Then, for most companies, buy for release flags (or self-host Unleash/GrowthBook if cost or data residency demands it) and run analysis warehouse-native. Build only the thin parts that are company-specific: codegen, stale-flag tooling, governance integrations, SSR bootstrap glue. A full in-house build is justified only at very large scale with a dedicated experimentation team.
critical; every change is audited with who, what, why.Local evaluation of a ruleset with 5,000 flags is microseconds per call. Precompile rules into a lookup structure
keyed by flag. Exposure events are batched (every 5 seconds or 50 events) and sent with fetch(..., { keepalive: true })
or navigator.sendBeacon on page hide. Deduplicate exposures per session per flag to reduce volume.
The flag service is down. What happens? Nothing visible. SDKs keep evaluating with the last snapshot; new processes load the snapshot from the CDN or disk cache; if all else fails, in-code defaults apply. Only changes stop propagating, so incident runbooks include a deploy-based fallback for critical kill switches.
How do you ensure a user sees the same variant on web and mobile? Bucket by the logged-in user ID with the same salt and hash on every platform, verified by the shared conformance suite. Before login you can only be consistent per device.
How do you test code with many flags? Tests set flags explicitly via an in-memory provider. Do not test all combinations; test each flag's on and off paths in isolation plus the combinations a prerequisite or layer makes possible. Storybook stories per variant help design review.
Can flags replace a config service? For a few runtime config values, yes. For large or structured configuration, no; flags are optimised for small values and fast propagation, and permissions belong in an entitlements system with its own audit model.
How do you stop an experiment from being rolled out with a bug? Guardrail metrics (error rate, INP, crash rate) evaluated automatically during the experiment, with auto-pause when a guardrail degrades beyond a threshold.
Spotted a mistake or a rights concern? Report an issue