Design an A/B Testing Platform
Understanding the Problem
🧪 What is an A/B testing platform? An experimentation platform lets product teams test a change on a random slice of users and measure whether it helped. It splits users between a control and one or more treatment variants, records which users saw which variant, joins that with what they did afterwards (purchases, clicks, sessions), and runs the statistics to say whether the difference is real or noise. Optimizely, Statsig, Eppo and the in-house platforms at large tech companies all fit this description.
It has three distinct parts, and interviews tend to go wrong when candidates only design one. Assignment is a low-latency online problem, almost identical to percentage rollouts in a feature flag system (see /system-design/feature-flags). Metrics computation is a large batch and streaming data problem. Analysis is a statistics problem, where the classic failure is not a slow system but a wrong answer.
Functional Requirements
Core Requirements
- Experimenters should be able to create an experiment: variants and their traffic split, who is eligible, and which metrics decide success (a primary metric plus guardrails like latency and crash rate).
- Applications should be able to get a user's variant for an experiment, consistently and quickly.
- The system should collect exposures and user events and compute each metric for each variant.
- Experimenters should be able to see results: the effect size with confidence intervals, whether it's statistically significant, and whether any guardrail is hurt.
Below the line (out of scope)
- Multi-armed bandits and personalization, which shift traffic toward winners while the test runs.
- The visual editor some web-testing tools offer for building variants without code.
- General-purpose product analytics dashboards. We compute experiment metrics, not every chart.
Non-Functional Requirements
Ask your interviewer for scale. We'll assume a large consumer company: 100 million daily active users, 1,000 experiments running at once, and 50 billion events per day flowing in from apps and services.
Core Requirements
- Assignment should add no meaningful latency: under a millisecond, with no network call on the request path.
- Assignment must be deterministic and sticky: a user stays in the same variant for the life of the experiment, across devices if they're logged in.
- Results should be statistically valid. The platform must not report false wins because of bad randomization, peeking or broken data. This matters more than speed.
- Full results should be available daily, within a few hours of the day ending. Health checks (is the split right? is something crashing?) should be near real time, within minutes.
- Many experiments should be able to run on the same users without interfering with each other.
Below the line (out of scope)
- Results updated by the second. Statistics on a few minutes of data aren't meaningful anyway.
Back-of-the-envelope:
Event volume. 50B events/day ÷ 86,400 s ≈ 580,000 events per second on average, with peaks perhaps 2-3× higher. At about 200 bytes each, that's 10 TB of raw events per day. Ingestion needs a durable log (Kafka) and cheap storage (S3 in a columnar format like Parquet).
Metrics work. The naive approach computes each metric for each experiment from raw events: 1,000 experiments × 20 metrics = 20,000 queries a day, each scanning terabytes. Even with columnar storage reading only the needed columns, that's petabytes scanned every day, which no one can afford. But notice that most experiments share the same metrics (revenue, sessions, clicks). If we compute each user's daily value for each metric once (100M users × a couple hundred metrics, most of them zero and not stored), every experiment can reuse it with a cheap join against its exposure list.
Sample sizes. Statistics sets the floor. To detect a 2% relative lift on a 5% conversion rate (5.0% → 5.1%) with standard settings (5% significance, 80% power), you need roughly 16 × p(1−p) / δ² = 16 × 0.0475 / 0.001² ≈ 760,000 users per variant. Experiments on small changes need a lot of traffic, which is why running many of them on overlapping users matters.
The second calculation is the key design insight: compute per-user metrics once and share them across experiments. Stating it early tells your interviewer you see this as a data engineering problem, not a "run a query per experiment" problem.