A/B Testing and Experimentation Platforms

A/B testing for system design: randomisation units, assignment, metrics and guardrails, sample size, peeking, and building an experimentation platform.

Intermediate 3 min read · Updated

An A/B test (online controlled experiment) randomly splits users between the current experience (control) and a change (treatment) and compares outcomes, so the difference can be attributed to the change rather than to seasonality or luck. An experimentation platform makes that safe and routine at scale: consistent assignment, exposure logging, metric computation, statistics and guardrails, for hundreds of concurrent experiments.

The pieces of an experiment

  • Hypothesis and primary metric: "The new ranker increases purchases per user." Decide this before launch.
  • Randomisation unit: usually the user (logged-in ID or a device ID); sometimes the session, the request, or a cluster such as a city.
  • Allocation: for example 50/50, or 5% treatment while ramping.
  • Guardrail metrics: latency, errors, revenue and complaints that must not get worse.
  • Duration and sample size: fixed in advance from the minimum effect worth detecting.

Assignment that stays consistent

Assign by hashing the unit ID with an experiment-specific salt: bucket = hash(experiment_id + user_id) mod 1000. The same user always lands in the same bucket, without storing assignments, and different experiments get independent splits because their salts differ.

log exposureRequestuser_idAssignment SDKhash(salt, user) → variantExperiment configallocation · targetingFeature codecontrol / treatmentExposure + outcome eventsMetrics + statisticsper variant
Assignment is a deterministic hash in the request path; exposure events are logged and joined with outcome events to compute metrics per variant.

Log an exposure event only when the user actually encounters the changed experience, and analyse those users. Analysing everyone assigned, including people who never reached the feature, dilutes the effect.

Statistics that matter in practice

  • Sample size and power: smaller effects need many more users. Detecting a 1% lift needs roughly four times as many users as detecting a 2% lift. Compute the sample size before launch.
  • Don't peek and stop early: checking p-values daily and stopping at the first significant result inflates false positives. Use a fixed horizon, or sequential testing methods designed for continuous monitoring.
  • Multiple comparisons: testing twenty metrics means one will look significant by chance. Pre-register the primary metric.
  • Variance reduction: methods such as CUPED use each user's pre-experiment behaviour to reduce noise, so experiments finish sooner.
  • Sample ratio mismatch (SRM): if a 50/50 split shows 50.8/49.2 with millions of users, assignment or logging is broken. Check it automatically and distrust results that fail.

When user-level A/B tests break

SituationProblemCommon approach
Marketplaces (riders and drivers)Treatment users compete with control users for the same supplyRandomise by region or time (switchback tests)
Social networksTreated users affect their friends' experience (network effects)Cluster randomisation by social graph communities
Long-term effectsNovelty boosts fade; learning effects take weeksLong-running holdout groups
Logged-out usersIDs change across devicesRandomise by device and accept some leakage

Running many experiments at once

  • Layers: experiments on unrelated surfaces run in independent layers, each with its own hash salt, so a user can be in many at once.
  • Mutual exclusion: experiments that touch the same feature share a layer and get disjoint traffic.
  • Config, not deploys: allocation lives in dynamic config (see feature flags), so ramping or killing an experiment doesn't need a release.
  • Automated guardrails: the platform can stop an experiment that breaches a guardrail threshold.

Where it’s used

Ranking changes

A new feed model is tested on 10% of users for two weeks on satisfied watch time, with latency and report rates as guardrails.

Pricing and promotions

City-level switchback experiments measure marketplace effects that user-level tests would bias.

UI changes

Checkout flow variants are tested with conversion as the primary metric and error rates as guardrails.

In an interview

  • State the randomisation unit, primary metric and guardrails before anything else.
  • Use deterministic hashing for assignment and log exposures.
  • Mention sample size, peeking and sample ratio mismatch checks.
  • Recognise network and marketplace effects and suggest cluster or switchback designs.

Further reading