Experimentation Platforms and Infrastructure Questions
Infrastructure for A/B testing and experimentation: assignment/bucketing, metric pipelines for experiments, guardrail and variance-reduction plumbing, and experiment result storage. Covers building the platform that powers trustworthy online experiments at scale. Distinct from the statistics of experiment analysis.
Given exposures(exposure_id, user_id, experiment_id, variant, assigned_at) and events(event_id, user_id, event_type, value, occurred_at), write a SQL query that computes the conversion rate (share of exposed users who generated a purchase event) per variant using a 14-day post-exposure window. Output variant, exposed_users, converters, conversion_rate.
Sample Answer
Direct answer
Compute conversion rate per variant by counting distinct exposed users per variant as the denominator, and counting distinct users who generated a purchase event within 14 days AFTER their own exposure timestamp as the numerator, being careful that the window is bounded on BOTH sides: it must start at the user's own assigned_at (excluding any purchase that happened before they were ever exposed) and end 14 days later (excluding anything past the window), anchored per-user, not to a single fixed calendar cutoff for everyone.
Structured elaboration
SELECT
e.variant,
COUNT(DISTINCT e.user_id) AS exposed_users,
COUNT(DISTINCT CASE
WHEN ev.event_type = 'purchase'
AND ev.occurred_at >= e.assigned_at
AND ev.occurred_at <= e.assigned_at + INTERVAL '14 days'
THEN e.user_id END) AS converters,
CAST(COUNT(DISTINCT CASE
WHEN ev.event_type = 'purchase'
AND ev.occurred_at >= e.assigned_at
AND ev.occurred_at <= e.assigned_at + INTERVAL '14 days'
THEN e.user_id END) AS REAL)
/ COUNT(DISTINCT e.user_id) AS conversion_rate
FROM exposures e
LEFT JOIN events ev ON ev.user_id = e.user_id
GROUP BY e.variant
ORDER BY e.variant;
Key points, complexity, and edge cases
The window is bounded on BOTH sides from each row's own assigned_at: occurred_at >= e.assigned_at excludes any purchase that happened before the user was exposed at all (a real risk for a repeat customer who purchased weeks earlier, unrelated to this experiment), and occurred_at <= e.assigned_at + INTERVAL '14 days' excludes anything past the attribution window. A query missing the lower bound will silently inflate the converter count with pre-exposure purchases; this is exactly the kind of bug that looks fine on a clean worked example (no test data with a pre-exposure purchase) and only surfaces once real, messy production data (a customer with purchase history predating the experiment) hits it. COUNT(DISTINCT ...) inside the CASE, rather than a plain COUNT, correctly avoids double-counting a user who made two purchases within the window. Complexity is a single-pass join and group-by, O(n) in the size of the joined exposures-and-events dataset; a user with no purchase events correctly contributes to exposed_users but not to converters, since the LEFT JOIN preserves them with no matching purchase row.
I executed this query in SQLite against a constructed test: two users per variant, one purchase inside the window (control, converts), one purchase exactly 15 days after exposure for the other variant (treatment, one day past the 14-day window). The query returned control: 2 exposed / 1 converter / 0.5 rate, and treatment: 2 exposed / 0 converters / 0.0 rate, correctly excluding the late purchase. I then added an adversarial case: a user exposed on 2026-02-10 with a purchase logged on 2026-01-05 (over a month before exposure). With only an upper-bound date filter (no occurred_at >= assigned_at), that pre-exposure purchase was incorrectly counted as a conversion (rate 1.0 for a single-user group); adding the lower bound above correctly excludes it (in a 3-user control group with that case added, converters = 1, not 2, giving a 0.333 rate instead of the wrong 0.667).
Trade-offs and pitfalls
A common mistake is joining events to exposures without restricting to event_type = 'purchase' inside the conversion condition, which would count ANY event (a click, a page view) as a conversion. An equally common and easy-to-miss mistake, confirmed above, is forgetting the LOWER bound on the attribution window entirely: filtering only on occurred_at <= assigned_at + 14 days looks correct and passes any test case that doesn't include a pre-exposure purchase, but silently inflates the converter count in production the moment a user with prior purchase history is exposed. Another mistake is using a single WHERE clause date filter (occurred_at <= '2026-01-15') instead of anchoring the cutoff per row to each user's own assigned_at, which silently breaks the moment users are exposed on different days, which they almost always are in a real rolling experiment.
Design a scalable assignment algorithm for experiments that must support sticky assignment across a user's devices and sessions, deterministic bucketing, and fast evaluation from many microservices. What data would the assignment call need, and how would you keep it both low-latency and consistent across regions?
Sample Answer
Direct answer
The assignment call needs the user's stable identifier, the experiment id (or the set of active experiments to evaluate), and a locally cached copy of each experiment's current configuration, and it stays low-latency and consistent across microservices by pushing configuration to every service ahead of time rather than looking it up centrally on each request.
Structured elaboration
- Sticky assignment across devices and sessions requires a stable identity to hash on. When a user isn't logged in, this usually means falling back to a device or cookie identifier, with an explicit reconciliation step at login time to decide which identity's prior assignment "wins" if the two disagree, since inconsistent handling here is one of the most common sources of a user seeing both variants across sessions.
- Deterministic bucketing: hash(namespace, experiment_id, user_id) mapped into the allocation, computed identically wherever it's needed, which means the hashing algorithm and the exact input string format must be specified precisely enough that a Python implementation and a Java implementation produce byte-identical results.
- Fast evaluation from many microservices: each service holds its own local, periodically refreshed copy of the experiment configs (pushed via a lightweight pub/sub update or pulled on a short interval), so an assignment lookup never makes a network call to a central service in the hot path; the trade-off is a brief staleness window (typically seconds) between a config change and every service seeing it.
- Consistency across regions: configuration replication needs to be eventually consistent across regions with a bounded lag, and the hashing itself, being a pure deterministic function of inputs, is naturally region-agnostic as long as every region has the same config and the same hash implementation.
Worked example
A user starts a session logged out (assigned via a cookie id), then logs in mid-session. If the login-time reconciliation naively re-hashes on the newly available user id, the user can flip from control to treatment mid-session, which is exactly the kind of assignment instability that breaks the causal interpretation of the experiment. The fix is to persist the FIRST assignment decision (whichever identity made it) as authoritative for that user going forward, rather than recomputing whenever a "better" identifier becomes available.
Trade-offs and pitfalls
Pushing full configuration to every service ahead of time trades a small staleness window for much better latency and resilience (a service can still evaluate correctly even if the central config service is briefly unreachable); the alternative, a synchronous central lookup, is simpler to reason about but adds a single point of failure and latency to every request. Multi-region consistency for the assignment reconciliation table specifically (which identity was assigned first) is the harder problem and usually needs a conflict-resolution rule (first-write-wins, keyed by timestamp) rather than assuming perfect synchronous replication.
Explain the difference between randomization and assignment in an experimentation platform. Compare simple (hash-based) randomization, stratified randomization, and block/random-permutation approaches, and give one practical scenario where each is the right choice.
Sample Answer
Direct answer
Randomization is the mechanism that decides how users get split into groups; assignment is the act of recording and looking up which group a specific user ended up in. Simple (hash-based) randomization treats every eligible user independently and equally likely to land in any variant. Stratified randomization first splits users into subgroups (country, new versus returning) and randomizes within each subgroup, so the split stays balanced across those subgroups even with a small sample. Block or permuted-block randomization forces a fixed ratio within consecutive chunks of arriving traffic, so the running split never drifts far from target even early in the ramp.
Structured elaboration
- Simple hashing: hash(user_id, experiment_id) mapped to [0, 1), then compared against a cumulative allocation threshold. Cheap, stateless, and the default choice whenever the eligible population is reasonably large and homogeneous, because with enough users the law of large numbers balances any covariate you didn't explicitly stratify on.
- Stratified randomization: randomize separately within each stratum (say, five countries), so each stratum individually gets the target split. This matters when a covariate is both unevenly distributed AND correlated with the outcome metric, and your total sample size isn't large enough to trust that simple hashing balances it by chance.
- Block/permuted-block randomization: guarantee, for example, that every consecutive batch of 100 arrivals contains exactly 50 control and 50 treatment, regardless of arrival order. This matters when you cannot tolerate a temporary imbalance even in the first hour of a ramp, for example if an early guardrail check depends on having a reasonably balanced sample immediately.
Worked example
A ride-hailing company launches a pricing experiment where 70% of daily traffic is in three home markets and 30% is spread thinly across twenty smaller markets. With simple hashing, the smaller markets might individually land at something like 40/60 splits purely by chance, because each one only has a few hundred users a day. Stratifying by market guarantees each market's own split stays close to 50/50, which matters here because the team specifically wants to report results per market, not just in aggregate.
Determinism matters here for a reason worth stating explicitly: the SAME user must land in the SAME group every time they're evaluated, or the experiment isn't measuring a stable treatment at all, and the "unit of randomization" (whatever a hash key is computed over: a user, a household, a session) is the thing that has to stay fixed for that guarantee to hold.
Trade-offs and pitfalls
Stratification and blocking add real engineering cost: every additional stratum is another dimension the assignment service must track state for (or, for hash-based stratification, another input folded into the hash key), and the analysis afterward must account for the stratification design (for example, using a stratified variance estimator) or it will understate the true precision gained. The common mistake is stratifying on a variable that turns out not to correlate much with the outcome, which pays the engineering cost without meaningfully reducing variance.
Design a scalable automated validity-check engine for an experimentation platform: it should run pre-launch and continuous post-launch checks covering SRM, instrumentation drift, delayed events, outliers, and contamination or leakage between variants. Describe the architecture, how rules execute, where machine-learning-based anomaly detection helps versus rule-based checks, and the remediation workflow when a check fails.
Sample Answer
Direct answer
A validity-check engine needs a rule-execution layer that runs a defined library of checks (SRM, instrumentation drift, delayed events, outliers, contamination) both once before launch and continuously during the run, an architecture that separates fast rule-based checks from slower machine-learning-based anomaly detection, and a remediation workflow that turns a failing check into a specific, actionable next step rather than just a red dot on a dashboard.
Structured elaboration
flowchart TD
Launch[Experiment Launch Request] --> PreCheck[Pre-launch rule engine]
PreCheck -->|pass| Live[Live Traffic]
PreCheck -->|fail| Block[Block launch, report reason]
Live --> Continuous[Continuous check scheduler]
Continuous --> RuleChecks[Rule-based: SRM, delayed events, outliers]
Continuous --> MLChecks[ML-based: drift, contamination anomaly scoring]
RuleChecks --> Remediation[Remediation workflow]
MLChecks --> Remediation
Remediation --> Pause[Auto-pause]
Remediation --> Page[Page owner]
- Rule-based checks (SRM, an event-volume floor, a delayed-events percentage) are cheap, deterministic, and explainable, which makes them a good fit for anything that needs to BLOCK a launch outright.
- ML-based anomaly detection earns its keep specifically where a fixed rule would be too rigid: detecting contamination between two experiments that share partial traffic, or flagging a metric drift pattern that doesn't fit a simple threshold (a gradual, compounding drift rather than a sudden step change). The trade-off is explainability: a rule-based check can tell an engineer exactly which threshold was crossed; an ML-based flag often needs a secondary "why did this fire" explanation layer or it becomes a black box nobody trusts.
- Remediation workflows: every failing check should map to a specific downstream action (block launch, pause new exposure, flag reporting as unreliable, page an owner), not just an entry in a generic alerts feed, since an alert with no clear next action trains people to ignore the whole system.
- Naming the drift taxonomy explicitly: "drift" isn't one thing; the engine should distinguish a mean shift (the metric's average level moved), a variance increase (the metric got noisier without necessarily moving on average), and a distributional change (the shape changed even if the mean looks stable), because each implies a different root cause and a different fix, and reporting all three under one generic "drift detected" label makes triage slower, not faster.
- An incident-response playbook for false positives specifically: because this engine runs continuously across every active experiment, it will generate false alarms; a documented playbook (check the last deploy, check SDK-version breakdown, check whether the same alert fired on an unrelated experiment at the same time, which would point at a platform-wide issue rather than an experiment-specific one) keeps a false-positive investigation fast and consistent rather than reinvented each time.
Worked example
A contamination check using a rule-based threshold (say, more than 5% user overlap between two experiments) would miss a subtler case: two experiments with only 2% direct user overlap but where that 2% happens to be disproportionately high-value users who account for a large share of the metric's variance. An ML-based anomaly model trained to weight overlap by its expected influence on the outcome metric, rather than raw user-count overlap, catches this case that a flat threshold rule would pass cleanly.
Trade-offs and pitfalls
Building the ML layer before the rule-based layer is a common overreach: most of the value (catching SRM, instrumentation drift, obvious contamination) comes from cheap, explainable rules, and ML-based anomaly detection should be reserved for the residual cases rules genuinely can't express, not used as the default approach everywhere. The other pitfall is under-investing in the remediation workflow itself: a technically excellent detection engine that only produces a dashboard nobody acts on has the same practical effect as no detection engine at all.
In one or two sentences, explain the multiple comparisons problem for a platform running many experiments and tracking many metrics per experiment. Then list two engineering controls, not statistical corrections, an experimentation platform could implement to reduce false discoveries.
Sample Answer
Direct answer
The multiple comparisons problem is that the more experiments and metrics you test, the more likely at least one shows a "significant" result purely by chance, even if nothing real is happening anywhere. Two engineering controls, beyond a statistical correction, are: capping how many metrics any single experiment can designate as "primary" (rather than letting a team declare a dozen primary metrics and cherry-pick whichever moved), and surfacing, alongside every significant result, how many total tests were run in that same batch or time window, so a viewer has the context to judge how surprising a single "win" really is.
Structured elaboration
Statistical corrections (Bonferroni, Benjamini-Hochberg) adjust the math after the fact; engineering controls change the SHAPE of what gets tested in the first place, which is often a cheaper and more durable fix. Limiting primary-metric count forces a real pre-commitment: a team that has to pick one or two metrics as the ones that decide ship/no-ship, with everything else demoted to secondary or guardrail status, structurally can't quietly cherry-pick a lucky metric from a long list after the fact. Surfacing the total-tests-in-context alongside any single result (something like "this metric was 1 of 40 tested today across the company") gives a reader the honest base rate needed to judge whether a single significant finding is more likely a real effect or an expected false positive given how many things were checked.
Worked example
A team runs an experiment with twelve metrics all nominally labeled "primary." One shows p=0.03. Reported in isolation, that looks like a clean win; reported alongside "twelve primary metrics were tested, and roughly one false positive at this rate is expected by chance alone even with zero real effect," the same number reads very differently, and the platform's job is to make that context impossible to miss rather than something a skeptical reader has to independently know to ask for.
Trade-offs and pitfalls
Capping primary-metric count too aggressively (forcing every team down to exactly one metric) can genuinely hurt teams whose product change legitimately affects two truly independent, equally important outcomes. The workable middle ground is a small cap (two or three) rather than one, paired with the requirement that the primary set be declared before launch, not adjusted afterward once results are in.
Unlock Full Question Bank
Get access to all Experimentation Platforms and Infrastructure interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.