A/B testing is how product teams ship changes with confidence. It's also how teams accidentally ship bad ideas because they misread results. This chapter is the playbook — design, sample size, reading results, and the traps that take down even experienced teams.
Designing an A/B test
- Hypothesis: "Showing the price more prominently will increase conversion by ≥ 5%."
- Primary metric: the one number that decides ship/don't ship. Secondary metrics watch for unintended damage.
- Unit of randomisation: usually the user — never the session, or you'll get the same user in both arms.
- Control vs treatment: treatment is what you're testing; control is the existing experience.
- Pre-register: write down the hypothesis, sample size, and stopping rule before the test starts. Stick to it.
Sample size & power
The sample size depends on three things: the baseline rate, the smallest effect you care about (MDE), and the power you want.
| Variable | Typical choice |
|---|---|
| α (significance) | 0.05 |
| 1 − β (power) | 0.80 |
| MDE (smallest effect to detect) | business-driven — 1%, 2%, 5% |
from statsmodels.stats.power import NormalIndPower# Baseline conversion 10% → wants to detect a 1pp absolute lift to 11%# Effect size as Cohen's hfrom statsmodels.stats.proportion import proportion_effectsizeh = proportion_effectsize(0.11, 0.10)n_per_arm = NormalIndPower().solve_power(effect_size=h, alpha=0.05, power=0.80, alternative="two-sided")print(f"~{round(n_per_arm):,} users per arm")# ~14,747 users per arm
The peeking problem
If you check the test daily and stop the moment p < 0.05, you'll see "significant" results from pure noise roughly 30% of the time. Stopping rules baked into traditional tests assume a single look at a fixed sample size.
- The fix: pre-commit to a sample size and only check the result at that point.
- Or: use sequential / Bayesian methods that account for repeated looks (e.g., always-valid p-values).
Reading the result
You ran the test. The dashboard says "treatment lift = +4.3%, p = 0.028". What do you actually conclude?
- Statistically significant? Yes — at α = 0.05.
- Confidence interval? "95% CI: +0.4% to +8.1%" — the true effect could realistically be much smaller.
- Practical significance? If 0.4% lift wouldn't justify ship, the result is statistically significant but practically inconclusive.
- Secondary metrics? Did latency get worse? Cancellation rate? Don't tunnel-vision on the primary.
- Pre-registered hypothesis? If you ran 12 segment cuts and one became significant, that's not a discovery — that's multiple-testing.
Segmentation traps
"The treatment didn't work overall, but it was great for users in the South!" — be careful.
- Every additional segment cut multiplies your false-positive rate.
- Pre-register segments you'll look at; treat post-hoc segments as hypotheses for the next test, not conclusions.
- Apply a Bonferroni or Holm correction if you're testing many segments simultaneously.
Real-world pitfalls
- Sample-ratio mismatch (SRM): if the actual split isn't ~50/50, your randomisation broke. Investigate before reading the result.
- Network effects: social products (think Facebook, Slack) violate independence — treatment users interact with control users.
- Novelty effects: any change shows a short-term lift just because it's different. Run long enough to see steady-state.
- Day-of-week effects: Mondays and Fridays behave differently. Run for at least one full week — ideally two.
- Outlier-driven results: one whale account can swing a small test. Cap or winsorise extreme values.
Key takeaways
- 01Pre-register: hypothesis, primary metric, sample size, stopping rule. Don't deviate.
- 02Compute sample size before starting — typical α=0.05, power=0.80, MDE business-driven.
- 03Don't peek-and-stop — it inflates false positives to ~30%. Pre-commit to one look.
- 04Always look at the confidence interval and practical significance, not just the p-value.
- 05SRM, novelty effects, day-of-week and outliers are the four most-common ways tests mislead.
