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.
What metadata should every experiment record to make its results reproducible and auditable later? List the core fields (owner, hypothesis, start/end dates, assignment seed, code/config version, variant definitions) and explain what each one is used for.
Sample Answer
Direct answer
Store an owner, hypothesis, start/end dates (planned and actual), the assignment seed and variant allocations, the variant definitions (what each variant literally configures, not just its traffic share), the code or configuration version being tested, and a status field tracking the experiment's lifecycle. Each field exists to answer a specific question later: "who do I ask", "what did we expect", "when was this live", "can I reproduce the exact assignment", "what did each arm actually change", and "what code was actually running".
Structured elaboration
A useful way to group the fields is by the question they answer:
| Purpose | Fields | Why it matters |
|---|---|---|
| Ownership and accountability | owner, team, approver | Someone must be reachable when the platform's own guardrail alerts fire six months later. |
| Reproducibility | assignment_seed, variant_allocations, variant_definitions, code_version, config_version | Without the exact seed and the exact code that ran, you cannot re-derive who was in which bucket, which makes any later re-analysis a guess. variant_allocations (the percentage split) and variant_definitions (the literal config, copy, or feature-flag values that make each arm different) are separate fields answering separate questions: allocations tell you HOW MANY users saw each arm, definitions tell you WHAT each arm actually was. A percentage split with no record of what "treatment" concretely configured is unreproducible even if the split itself is perfectly logged. |
| Timing | planned_start, planned_end, actual_start, actual_end, ramp_schedule | Actual dates almost always diverge from planned ones (a ramp gets paused, a launch slips); both need to be recorded, not just one. |
| Intent | hypothesis, primary_metric, guardrail_metrics | A pre-committed hypothesis and metric list is what lets you tell a genuine finding from a post-hoc story fitted to whatever moved. |
| Governance | status (draft, running, paused, concluded, rolled back), compliance_tags | Status transitions are themselves an audit trail: an auditor should be able to see that an experiment was paused on a specific date and why. |
Worked example
Six months after an experiment ships, a data scientist is asked "did we really test this against a 50/50 split, or was it 90/10 during the ramp?" Without stored assignment_allocations per time window, the honest answer is "we don't know." With a metadata table that logs allocation changes and their timestamps, the scientist can reconstruct exactly which users saw the true 50/50 config used in the final analysis versus the earlier 90/10 ramp period, and exclude the ramp period from the reported result if it was not part of the intent-to-treat population. A second, equally common question is "what did treatment actually DO differently from control?" If only variant_allocations was stored (50/50) and variant_definitions was never captured, nobody can answer that without archaeology through old deploys or config diffs; a stored variant_definitions field (for example, a JSON blob recording "control: default checkout order; treatment: payment-method-first order") answers it directly from the metadata table itself.
Trade-offs and pitfalls
Storing too little metadata (just an experiment name and two dates) makes every later question a guess. Storing too much freeform metadata without a fixed schema makes it unqueryable at scale, because nobody agrees on field names across teams. The practical middle ground most platforms converge on is a small fixed core schema (the fields above) plus an open key-value extension field for team-specific context, so cross-team queries and dashboards can rely on the fixed fields while individual teams still get flexibility.
Define Sample Ratio Mismatch (SRM). What simple automated checks would you put in place to catch it both before an experiment ramps and continuously while it runs, and why does catching it early matter?
Sample Answer
Direct answer
Sample Ratio Mismatch (SRM) is when the observed split of users across variants differs from the intended split by more than chance would explain, for example seeing 5,150 versus 4,850 users on a supposed 50/50 test. It matters because SRM is a symptom that the assignment or logging pipeline is broken in a way that almost certainly also biases every other metric in the experiment, so a result computed on top of an SRM-positive experiment cannot be trusted regardless of how significant it looks.
Structured elaboration
The standard automated check is a chi-square goodness-of-fit test comparing observed counts per variant against the expected counts implied by the configured allocation, run both once before the ramp (a pre-launch dry run with no real treatment applied yet) and continuously during the run (for example, hourly, on cumulative counts).
χ2=∑iEi(Oi−Ei)2
where Oi is the observed count in variant i and Ei is the expected count under the configured allocation. A conventional trigger threshold is a p-value below roughly 0.001 (deliberately stricter than the usual 0.05, because this check runs continuously and needs a low false-alarm rate to stay trustworthy), which corresponds to a fairly large chi-square statistic even at moderate sample sizes.
Why catch it early: SRM almost never means "the treatment made fewer people eligible," it means something upstream is dropping or misrouting users differentially by variant. Common root causes include a logging pipeline that fails more often for one client version that happens to be overrepresented in one arm, a redirect or bot filter that only fires for one variant, or an assignment bug that isn't actually independent of some other property of the user. Any of those same root causes will also bias the outcome metrics you actually care about, not just the headcount, so an experiment with SRM should be treated as unmeasurable until the cause is found and fixed, not merely "significant with an asterisk."
Worked example
10,000 users are configured for a 50/50 split; the platform observes 5,150 in control and 4,850 in treatment.
χ2=5000(5150−5000)2+5000(4850−5000)2=50001502×2=9.0
For one degree of freedom, a chi-square statistic of 9.0 corresponds to a p-value of roughly 0.0027, well past a 0.001 threshold's neighborhood and certainly past the usual 0.05 bar. This experiment should be flagged and investigated before any metric from it is reported.
Trade-offs and pitfalls
Setting the alert threshold too loose (using the ordinary 0.05 bar) produces frequent false alarms on a check that runs continuously over many time windows, training the team to ignore it; setting it far too strict misses real, smaller-magnitude assignment bugs. The other common mistake is checking SRM only once, at the end of the experiment: a bug that appears for three days in the middle and then gets fixed can wash out in the cumulative count while still having corrupted the metrics computed during those three days.
Design a streaming ingestion and near-real-time metric-computation pipeline for experiment telemetry that handles a very high event rate with at-least-once delivery, deduplication, schema evolution, and late-arriving or out-of-order events. Describe the components (producers, message broker, stream processors, storage, serving layer), and how you would reconcile a low-latency 'monitoring' view against a slower, high-accuracy 'reporting' view of the same metric.
Sample Answer
Direct answer
A streaming ingestion pipeline for experiment telemetry needs a message broker (like Kafka) for durable at-least-once delivery, stream processors that deduplicate by a stable event id and handle schema evolution via a shared schema registry, and a storage/serving layer that produces near-real-time aggregates for monitoring while a separate, slower batch path produces the authoritative, fully-reconciled numbers used for the final read-out.
Structured elaboration
flowchart LR
Clients[Client/Server SDKs] --> Broker[(Message Broker: Kafka)]
Broker --> StreamProc[Stream Processor: dedup, enrich]
StreamProc --> Hot[(Hot store: near-real-time aggregates)]
StreamProc --> Cold[(Cold store: raw immutable events)]
Cold --> Batch[Daily batch job: authoritative recompute]
Batch --> Reporting[Reporting metric store]
Hot --> Monitoring[Live monitoring dashboard]
SchemaReg[(Schema Registry)] --- StreamProc
- At-least-once delivery plus deduplication: the broker guarantees no event is silently lost, but that guarantee comes paired with the possibility of duplicate delivery on retry; the stream processor deduplicates using a stable event id (assigned at the client, not at ingestion, so a genuine retry of the same logical event carries the same id), typically via a bounded time-windowed dedup cache rather than an unbounded one that would grow forever.
- Schema evolution: every event carries a schema version, and the schema registry enforces that changes are additive only, so an older event and a newer one can both be processed by the same pipeline code without breaking.
- Late-arrival handling: the hot, near-real-time aggregate accepts events within a bounded lateness window (a watermark), and any event arriving after that window still lands in the cold, immutable raw store and gets folded into the next batch recompute, so late data isn't lost, it's just not reflected in the FAST view.
- Reconciling monitoring versus reporting: the hot store's numbers are approximate and fast, meant for guardrail alerting and live dashboards; the cold store plus batch job produces the authoritative number used for the actual ship decision, and the two are expected to differ slightly, which the platform should surface explicitly rather than let a viewer assume both are the same precision.
- Concrete freshness SLAs: a common split is a roughly 5-minute freshness target for the hot monitoring path (with historical rollups and lineage attached so a stale-looking number can be traced back) and a sub-one-hour freshness target for a daily-batch variant that does an incremental recompute on top of the previous run rather than a full reprocess every time, reserving a full recompute for schema fixes or backfills.
- Exactly-once semantics with named tooling: stream processors like Flink or Spark Structured Streaming provide exactly-once sink guarantees when configured correctly (checkpointing plus an idempotent or transactional write to the sink), which is what keeps the deduplication logic above from having to do all the work alone; watermarking in these frameworks is what implements the bounded lateness window described above.
- Metric registry integration: the same schema registry that governs event shapes should also version the METRIC definitions computed from those events, so a metric's computation logic, not just its event inputs, is tracked and queryable, which is what lets an offline research team later confirm exactly which formula produced a historical number and catch a silent computation bug through reproducibility checks rather than trusting the number by default.
Worked example
At 200k events per second, holding an unbounded deduplication window in memory is infeasible; a bounded window (say, 24 hours) trades a small risk of missing a very late duplicate for a manageable memory footprint, which is the right trade given that the authoritative batch recompute over the full immutable raw log catches any duplicate the bounded streaming dedup missed.
Trade-offs and pitfalls
Trying to make the streaming path both fast and perfectly accurate is the most common architectural mistake at this scale; it's cheaper and more honest to explicitly split "fast and approximate" from "slow and authoritative" than to over-engineer the streaming path to try to be both, which usually ends up being neither fast nor fully correct. The other pitfall is under-sizing the late-arrival watermark window for the traffic pattern actually observed (mobile clients batching events can introduce longer delays than a naive watermark assumes), silently excluding legitimate late data from the fast view more often than intended.
Write pseudocode (or Python) for an evaluation harness that A/B tests a recommendation model behind several microservices at very large scale. It should route users to variant or control, collect the event stream (impressions, clicks, sessions), compute daily metrics with confidence intervals, and handle delayed events gracefully. Explain your key implementation choices.
Sample Answer
Direct answer
Build the harness around a deterministic router (hash-based, keyed by user and experiment id), a per-day-and-variant aggregation store keyed by the event's own timestamp (not the time it was processed), and a confidence-interval calculation over that daily aggregate, explicitly allowing a delayed event to land in the correct historical day's bucket even if it arrives after that day's report already shipped, and explicitly handling the case where a day/variant bucket has clicks recorded with zero impressions (a pure delayed-click day).
Structured elaboration
import hashlib, math
from collections import defaultdict
def assign(user_id, experiment_id):
h = int(hashlib.sha256(f"{experiment_id}:{user_id}".encode()).hexdigest()[:8], 16)
return "treatment" if (h % 100) < 50 else "control"
class EvalHarness:
def __init__(self, experiment_id):
self.experiment_id = experiment_id
self.daily = defaultdict(lambda: {"impressions": 0, "clicks": 0})
def route(self, user_id):
return assign(user_id, self.experiment_id)
def record_event(self, user_id, day, event_type):
variant = self.route(user_id)
if event_type == "impression":
self.daily[(day, variant)]["impressions"] += 1
elif event_type == "click":
self.daily[(day, variant)]["clicks"] += 1
def daily_ctr_with_ci(self, day, variant, z=1.96):
d = self.daily[(day, variant)]
n = d["impressions"]
if n == 0:
return {"ctr": None, "ci_low": None, "ci_high": None, "n": 0}
p = d["clicks"] / n
se = math.sqrt(p * (1 - p) / n)
return {"ctr": p, "ci_low": p - z*se, "ci_high": p + z*se, "n": n}
Key implementation choices: routing is a pure, stateless function of user and experiment id, so the same user always gets the same variant across every call, with no shared mutable state needed for assignment itself; the experiment_id is stored on the instance in __init__ so route() can reference it; delayed events are keyed into whichever day's bucket their OWN event day implies, meaning a per-day report has to be treated as revisable (not final) until a defined freshness cutoff has passed, rather than assuming today's report is the permanent, final number for today; daily_ctr_with_ci explicitly guards the zero-impressions case (a day with delayed clicks but no new impressions), returning a None-valued placeholder rather than crashing on a division by zero, since a click-only day is a real, expected shape of data in this harness, not an error condition.
Worked example (executed)
Simulating 50,000 users with a true control CTR of 10% and treatment CTR of 11.5% (a real +15% relative lift), with 5% of clicks intentionally delayed to the following day: the harness correctly split traffic close to 50/50 (25,054 versus 24,946 impressions), measured day-0 CTRs of 9.38% (control) and 11.15% (treatment), consistent with the true rates minus the roughly 5% of clicks that landed in day 1 instead, and querying day 1 for either variant correctly returned {"ctr": None, "n": 0} rather than raising, since day 1 recorded only delayed clicks and zero new impressions in this simulation.
Trade-offs and pitfalls
The most common mistake in a harness like this is keying delayed events by the processing time rather than the event's own timestamp, which silently shifts metrics between days and makes any single day's number impossible to trust until enough time has passed for its delayed events to fully arrive; this harness deliberately keys by the event's own day for exactly that reason. A second common mistake, the one this version fixes, is assuming every day/variant bucket that has any activity also has impressions to divide by; a pure delayed-click day breaks that assumption and needs an explicit guard rather than an implicit ZeroDivisionError. The remaining cost is that any "today's" report is necessarily provisional until a defined lateness window closes, which has to be communicated clearly to whoever is reading a same-day dashboard number, or they'll mistake a still-settling number for a final one.
Before a new metric-computation pipeline becomes part of the experimentation platform, what QA process would you run on it: unit tests, integration tests, golden-file regression tests, and a live A/B smoke test? Describe what each layer catches that the others would miss.
Sample Answer
Direct answer
Before a new metric-computation pipeline ships, run unit tests on the individual transformation logic, integration tests against a realistic end-to-end sample of raw events, golden-file regression tests that lock in known-correct output for a fixed input, and a live A/B smoke test comparing the new pipeline's output against the existing production pipeline on real (but not yet trusted) data before fully cutting over.
Structured elaboration
- Unit tests: verify individual pieces in isolation (the deduplication logic, the attribution-window filter, the aggregation function) against small, hand-constructed inputs with known expected outputs, which is where a logic bug (like an off-by-one in the attribution window) is cheapest to catch.
- Integration tests: run the full pipeline against a realistic synthetic dataset that includes the messy edge cases production data actually has (duplicate events, out-of-order arrivals, users exposed to multiple experiments), verifying the end-to-end output rather than any one component.
- Golden files: a fixed, versioned input dataset paired with its known-correct output, re-run on every pipeline change; if the new code produces a different result on the same input, that's either an intentional, reviewed change or a regression, and the test forces someone to explicitly acknowledge which.
- Live smoke tests: before fully replacing the existing pipeline, run the new one in parallel on real production data and diff its output against the existing pipeline's numbers for a subset of experiments, since a synthetic test dataset, no matter how careful, can miss a real-world data shape nobody thought to construct by hand.
Each layer catches something the others miss: unit tests catch logic bugs cheaply but can't catch an integration mismatch between components; integration tests catch component-interaction bugs but use synthetic data that might not reflect real-world messiness; golden files catch unintentional regressions but only for the specific cases already captured; live smoke tests catch anything that's specific to real production data's actual shape, at the cost of only running after the code is otherwise believed correct.
Worked example
A new metric pipeline passes every unit and integration test cleanly, since the synthetic test data was constructed with clean, well-ordered events. In the live smoke test, its output for one experiment diverges meaningfully from the existing pipeline's, tracing back to a real production pattern the synthetic data never included: a small fraction of users whose exposure event arrives up to 40 minutes after their first conversion event, due to a specific mobile client's batched event upload behavior. This ordering violates an assumption ("exposure always precedes the outcome event") the new pipeline's join logic quietly depended on, which no amount of hand-constructed synthetic testing surfaced.
Trade-offs and pitfalls
Skipping the live smoke-test stage to move faster is the most common shortcut, and it's exactly the stage that catches real-world data shapes nobody anticipated; synthetic tests, however thorough, are bounded by what the test author thought to include. The cost of the smoke-test stage is running two pipelines in parallel for a period, which is real infrastructure overhead, but it's the only layer that validates against ACTUAL data rather than someone's mental model of what the data looks like.
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.