Skip to content
Tech Interview Prep
Technical interview guide

A/B Testing

Applying hypothesis testing to compare two product/design variants: sample size, statistical power, and the traps of stopping early.

Minutes to read
3
Practice MCQs
25
Interview Q&A
25
Edition
v7
Editorial status
Reviewed

Scope: Practitioner and standards references current as of 2026-09: the experimentation-platform literature, NIST/SEMATECH e-Handbook, the 2016 ASA statement on p-values, SciPy, and statsmodels.

Overview

Curated: · Written: · Reviewed:

A/B Testing

In one line

A randomised comparison of two variants, analysed by assigned arm on one pre-registered primary metric, used when the decision depends on the causal size of the effect. Reach for it when the change can be randomised at a unit that does not leak and traffic can detect the smallest effect that would change the decision.

Key definitions

  • Randomisation unit: the level at which assignment is made. It must be at least as coarse as the level at which treatment leaks between users.
  • ITT (intention to treat): analysis by assigned arm, whatever users actually experienced.
  • SRM (sample ratio mismatch): observed split differs from the intended split. A chi-squared check that blocks the readout.
  • MDE (minimum detectable effect): the smallest true effect the test detects at the chosen power and alpha.
  • Guardrail: a metric with a pre-agreed stop threshold. It can stop a ship but never makes one.
  • Surrogate: a short-term metric validated against the long-term outcome it stands for.

Formulas and complexity

nper arm≈(z1−α/2+z1−β)2 [p1(1−p1)+p2(1−p2)](p2−p1)2n_{\text{per arm}} \approx \frac{(z_{1-\alpha/2}+z_{1-\beta})^2\,[p_1(1-p_1)+p_2(1-p_2)]}{(p_2-p_1)^2}

At a 3.2% baseline, a 10% relative lift (3.52%), two-sided alpha 0.05 and 80% power, this gives about 49,800 per arm.

θ=cov⁡(y,xpre)var⁡(xpre),y~=y−θ (xpre−xˉpre)\theta=\frac{\operatorname{cov}(y,x_{\text{pre}})}{\operatorname{var}(x_{\text{pre}})},\qquad \tilde y=y-\theta\,(x_{\text{pre}}-\bar x_{\text{pre}})

CUPED uses only a strictly pre-treatment covariate. With events logged from N users, the effective sample is nearer N than the event count.

How it works

Assignment is a deterministic hash of a stable id, logged at decision time and sticky across sessions. The SRM check runs before any metric is read. Analysis is by assigned arm. Any trigger is evaluated and logged identically in both arms.

no yes Stable user id Hash assignment Control Treatment Log exposure and triggers SRM check passes Block readout and debug ITT analysis on primary metric Decision rule with guardrails

When to use and when not to

SituationUse A/BChoose something else
Visible UI change, users randomisableYes, randomise by userNo
Marketplace or shared resourceNo, unit leaksMarket-level randomisation or switchback
MDE at or below a plausible effectYesPlausible effect far below MDE: monitor or evaluate qualitatively
Long-term outcome onlyYes with a validated surrogateUnvalidated surrogate: long-term holdout
Heavy-tailed revenueCUPED plus a pre-agreed capPost-hoc cap chosen after seeing data
Legal or security obligationNoShip under the obligation

Traps interviewers probe

  1. Conditioning on a post-treatment variable. Restricting analysis to users who reached a step the change itself affects reintroduces selection, and the restricted comparison can reverse the overall result. Fix: analyse every assigned user. Use only pre-trigger eligibility for a restriction.
  2. Stopping at the first significant look. Repeated looks at p < 0.05 inflate false positives, and continuous monitoring at a nominal 5% can reach roughly 30%. Fix: pre-register looks with an alpha-spending function such as O'Brien-Fleming, or use always-valid inference.
  3. Reading through an SRM. A mismatched split means assignment, logging or filtering is broken. Fix: block the readout, find the cause, and do not adjust the analysis for the ratio.
  4. Analysing events as independent. Two million events from fifty thousand users gives an interval several times too narrow. Fix: aggregate to the user, or use the delta method or clustered errors.
  5. Segment fishing. Twelve unplanned segments at alpha 0.05 give about a 46% chance of at least one false positive. Fix: pre-register segments and test the interaction.

Interview tips

Open with the design and the decision: "A randomised comparison by assigned user, analysed ITT on one pre-registered metric, with guardrails and a rule written before launch." Then name the first check you run, which is the SRM.

Expect these follow-ups: why the ratio check comes first; how you would detect interference and switch to a switchback; why a significant day-two result is not a 12% claim; how a long-term holdout reconciles claimed wins with the measured trajectory; and how you would size a test with low traffic.

30-second outline: state the hypothesis and unit. State the assignment and the ITT analysis. State the SRM gate. State the primary metric, its CI and the guardrail thresholds. State the decision rule for significant, non-significant and harmful outcomes.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.