Concepts / A/B Testing in Production

A/B Testing in Production

Online testing, also called live testing, asks what happens when that algorithm is actually part of the product and real users interact with it.

  • Programming

A Model That Looks Good on Paper

Imagine you have built two versions of a recommendation system. One performs well when you check its predictions against a set of examples you already collected. The question is whether that good score is enough to release it to every user of your website. This article explains why the answer is usually no, and what a team does next.

What do you think happens?

A new algorithm beats the current one on a test set. Should you switch all users to it right away?

  • Yes, a better test score means it is better for users

  • No, the test score alone does not show how users will respond to it

  • Yes, as long as the test set is large enough

Reveal answer
Answer:

No, the test score alone does not show how users will respond to it.

Offline evaluation is only the first step for a user-facing machine learning system. Predictions that look good on a test set can still behave differently once they are placed inside a real product, so the usual next step is online testing.

Offline Evaluation and Its Test Set

Much of machine learning evaluation begins with a test set. You collect a set of examples ahead of time, let your algorithm make predictions on them, and measure how well those predictions match what actually happened. This process is called offline evaluation. Its main advantage is that it lets you check an algorithm's predictions without exposing anything to real users.

Offline evaluation is therefore a controlled check. The examples were gathered before the test, the algorithm's outputs are compared against outcomes that already happened, and no live customer sees a different experience while this is going on.

Two Stages, Two Questions

For a user-facing system, offline evaluation is only the first step. The two stages answer different questions. Offline evaluation asks how well an algorithm's predictions match a test set collected beforehand. Online testing, also called live testing, asks what happens when that algorithm is actually part of the product and real users interact with it. Online testing evaluates the consequences of employing an algorithm in the overall system, not just the accuracy of its predictions.

AspectOffline evaluationOnline testing
Data sourceA test set collected ahead of timeReal users interacting with the product
What is measuredHow well predictions match what happenedConsequences of the algorithm in the overall system
Real users exposedNoYes
Question answeredDo the predictions match the test set?What happens when the algorithm is part of the product?

Offline evaluation and online testing compared for a user-facing system

Why Live Users Change the Picture

Changing the recommendations or search results a website shows its users can drastically change how those users behave. A recommendation list that performs well in an offline test may shift what people click, what they buy, or how long they stay. Those shifts can ripple through the rest of the system in ways no one predicted.

This is the central reason online testing exists. It is designed to discover unexpected consequences when users interact with a model. A test set cannot show these effects, because the test set does not respond to what the system shows. Real users do.

Read the loop from the top. The system shows recommendations, users respond, and those responses become part of what the system sees next. Because the change in behavior is produced by the algorithm itself, its effects can accumulate in ways a single offline check would never capture.

How an A/B Test Divides Users

A/B testing is a form of blind user study. Without their knowledge, a selected portion of users is given a website or service that uses algorithm A, while the rest of the users are given the same kind of service using algorithm B. Because users do not know which version they see, their behavior reflects what happens in ordinary use rather than how they behave when they know they are being tested.

In many settings, algorithm A is a new model and algorithm B is the established system. The established system acts as the baseline that the new model must be compared against.

Follow the flow in the diagram. Incoming users reach the test, and a selected portion is routed to group A while the rest go to group B. For both groups, relevant success metrics are recorded over a set period of time. When that period ends, the metrics for algorithm A and algorithm B are compared, and a choice between the two approaches is made according to those metrics.

Tracing One Test From Start to Decision

Worked example

A recommendation list tested against the current system

A video site has an established recommendation system (algorithm B) and a new model (algorithm A) that scored well on its offline test set. The team wants to know whether the new model should replace the old one.

  1. 1
    Select a portion of users

    A selected portion of users is given the site with algorithm A. The rest receive the same kind of site using algorithm B. Users are not told which version they see.

  2. 2
    Record success metrics for both groups

    For each group, the team records metrics such as clicks, purchases, and how long users stay, since these are the kinds of behavior the recommendations can shift.

  3. 3
    Wait for the set period to end

    Metrics are collected over a set period of time rather than at a single moment, so the comparison covers ordinary use across that window.

  4. 4
    Compare and choose

    The metrics for algorithm A and algorithm B are compared, and the choice between the two approaches is made according to those metrics.

Result

The team does not decide from the offline score. If group A shows more clicks but fewer purchases than group B, the metrics point to a trade-off, and the team must weigh those results before choosing.

Mistakes Beginners Make With Test Results

  • Common mistake

    Treating a strong offline score as proof that the model is ready for all users

    What it looks like

    A model beats the current system on last month's labeled examples, so it is shipped to everyone the same day.

    Why it fails

    Offline evaluation checks predictions against a test set. It does not show the consequences of the algorithm inside the overall product.

    Do this instead

    Use offline evaluation as the first step, then run online testing to see how real users respond.

  • Common mistake

    Assuming users behave differently because they know they are being tested

    What it looks like

    Users are told they are part of an experiment, and the team reads their behavior as typical.

    Why it fails

    A/B testing is a blind user study. Because users do not know which version they see, their behavior reflects ordinary use.

    Do this instead

    Keep the test blind so that the recorded behavior represents what happens in normal use.

  • Common mistake

    Judging the two groups before the set period is over

    Why it fails

    The metrics for algorithm A and algorithm B are compared when the set period ends, so an early snapshot may not reflect the full comparison.

    Do this instead

    Record metrics for both groups over the planned period, then compare them.

  • Common mistake

    Assuming a single metric tells the whole story, when clicks, purchases, and time spent may move in different directions

Beyond a Fixed Split: Bandit Algorithms

A/B testing is not the only way to run online tests. There are more elaborate mechanisms for online testing that go beyond A/B testing, and bandit algorithms are one example. At this stage you only need to know that these approaches exist. The mechanics of how they choose between options are a topic for further study.

Practice: Classify Each Evaluation Question

EASY

A team has a new recommendation model. For each of the following, decide whether it is an offline evaluation question or an online testing question, and say why: (1) Does the model's prediction match outcomes in last month's collected examples? (2) After the model is placed in the product, do users buy more or stay longer? (3) Does the new model make the same predictions as the old one on a test set? (4) Which algorithm should the selected portion of users receive, and how do the two groups' metrics compare?

Hints
  • Ask whether real users are involved in the question.
  • Offline evaluation uses a test set collected beforehand, while online testing looks at consequences inside the overall system.
  • Metrics compared over a set period belong to the A/B testing flow.

Key Takeaways

  • Offline evaluation checks an algorithm's predictions against a test set collected beforehand, without exposing anything to real users, and it is only the first step for a user-facing system.
  • Online testing evaluates the consequences of an algorithm inside the overall product, because changes to what users see can have unexpected effects on what they click, buy, and how long they stay.
  • A/B testing is a blind user study: a selected portion of users receives algorithm A, the rest receive algorithm B, success metrics are recorded for both over a set period, and the two are compared to make a choice.
  • Bandit algorithms are a more elaborate option for online testing beyond A/B testing; this article introduces them only as an existing alternative.

Related concepts

More concepts starting with A