AlgoViz

Design an A/B testing platform

hard 45 min

Show each person one version of a feature, always the same one, measure what they do, and say honestly whether the difference is real, for a thousand experiments at once.

Video lesson · Chapter 1 of 5

A green checkout button needs a trustworthy comparison

0:00 / 4:34

Theory

Read or listen first. About 2 min.

What it is

An A/B testing platform gives different people different versions of a product by chance, records what they do, and compares the groups. Because chance chose the groups, a large enough difference must come from the version.

It has two halves. One decides which version a person sees, in microseconds, everywhere. The other collects events and does statistics, in hours. They meet in one place: a record that says who was really shown what.

Why it exists

Comparing this week with last week mixes the change with everything else that happened: holidays, prices, weather. Two groups at the same time share all of that.

A platform also protects people from bad changes. A new version starts with 1% of them, and can be switched off in seconds.

A short history

  1. 2007

    Kohavi, Henne and Sommerfield publish a practical guide to controlled experiments on the web at KDD.

  2. 2010

    Google engineers describe overlapping layers, which let many experiments share the same traffic.

  3. 2013

    Deng, Xu, Kohavi and Walker describe CUPED, which uses data from before an experiment to reduce noise.

  4. December 2015

    Johari, Pekelis and Walsh post a paper on always valid inference, for teams that look at results every day.

  5. 2019

    Fabijan and others publish a guide to finding the causes of sample ratio mismatch at KDD.

Words to know

Variant
One version of the feature. The unchanged one is the control.
Bucket
A number from 0 to 9,999 made from a person's id.
Salt
Text added before hashing, so each experiment shuffles people differently.
Exposure
The record that a person reached the place where versions differ.
Sample ratio mismatch (SRM)
Group sizes that the planned split can hardly explain.
Power
The chance of noticing an effect of a given size, usually planned at 80%.
Minimum detectable effect (MDE)
The smallest effect the plan is able to notice.
Guardrail
A metric that must not get worse, such as errors or page time.

Solve it like an interview

New to it? Start with Approach. Revising? Go straight to the mock.

  1. 1ApproachWhat this question tests, where it gets hard, and how to spend the time.
  2. 2ScopeAsk what changes the design, then commit to a short list.
  3. 3NumbersWork out a number when the answer changes what you build.
  4. 4API and dataThe contract first, then the data that serves it.
  5. 5DesignStart with the smallest system that works. Change it only when something breaks.
  6. 6Deep divesCompare the options before you open them, then say which you would pick.
  7. 7Explain your choicesAnswer first. Then compare your reasoning.
  8. 8By levelThe same question is judged differently for mid, senior and staff.
  9. 9MockAnswer against the clock, then score yourself.

Understand it

Two bird feeders and a coin
Where do more birds eat?

The coin makes it fair, the ring keeps it steady, and the count of rings shows whether to trust it.

The task

What are we building?

A service like Optimizely, LaunchDarkly, Split, VWO, Statsig, Amplitude Experiment or Eppo. (Google Optimize was another; it closed on 30 September 2023.) Teams describe an experiment, the platform splits people, records results and reports them. Feature flags come with it, because a flag is the switch that an experiment turns.

  • Assign

    Same person, same version, with no network call.

  • Record

    Exposures and events, without losing or doubling them.

  • Judge

    Effect, uncertainty, and whether the data can be trusted.

  • Control

    Ramp up, exclude, hold out, and stop in seconds.

The hard part

Being believed

Every part can work and the answer can still be wrong: a missing exposure, a group that lost its slowest phones, a team that stopped on a lucky day. The hard part is building a pipeline that notices its own faults, at a thousand experiments at once.

The finished system

Where the design ends up

The whole system

Product teams use the config service, which stores plans in PostgreSQL and publishes a config file to a CDN. Apps with an SDK inside read the config and decide locally. They send exposures and events to ingest, then Kafka. From Kafka, events go to the warehouse, read hourly by the stats engine, and to live guardrails. The stats engine checks the data and writes results to PostgreSQL. Guardrails can mark an experiment as paused there, and the config service publishes it.
Blue decides, pink measures, orange protects. The Design tab shows what forces each box.

Where each idea is taught

IdeaHereFull page
Config near usersOne file at the edgeCDN
Events through a logExposures and eventsLog-based queues
Windows over streamsLive guardrailsStream processing
Scanning columnsHourly statisticsOLAP
Counting an event onceEvent idsIdempotency
Counting clicks at scaleA neighbour problemAd click aggregator

The Interviews page follows the nine tabs: Approach, Scope, Numbers, API and data, Design, Deep dives, Explain, By level and Mock.

Summary

The whole topic in one minute.

Assignment is a pure function of a person's id and the experiment's salt, so no server has to remember it. One hash decides whether the person is in the experiment, and another decides the version. The SDK evaluates both locally, from a config file.

Results are only as good as the exposure record. Check the sample ratio before you look at any metric, fix the sample size or use a method that allows peeking, and correct for many metrics. Stop harmful versions with fast guardrails, which are separate from the hourly statistics.

  • Assignment is a hash, not a stored row: nothing to look up, nothing to lose.
  • Use one hash for who takes part and another for which version, or ramping breaks the split.
  • Record exposure where versions differ, in both groups, in the same way.
  • Look at the sample ratio first. If it is off, show no result.
  • Choose the sample size, or a method made for daily looking, before the start.

Sources