Sub topic 12
Testing feed changes with A/B experiments
A feed team can't tell by reading code whether a new ranking change is an improvement. The change might raise one number and hurt another, or help one group of users and harm a different group. Platforms settle these questions with controlled experiments, usually called A/B tests. This chapter covers how they are set up, which metrics they watch, how to read the results, and where they mislead.
This chapter assumes you know the pipeline from earlier chapters (candidate generation, scoring, re-ranking), that a probability is a number between 0 and 1, and that you can read short Python. It does not assume formal statistics training. Each statistical term is explained when it first appears.
Why offline checks are not enough
Before any live test, teams evaluate a new model offline. They replay logged data and ask whether the model would have predicted past likes and hides well. This is cheap and safe, but it has a limit. Logged data only records what the old ranker chose to show. A new ranker will show different posts, and the logs say nothing about how people would react to those.
An online experiment fixes this by showing real users the new behavior and measuring what they do. Offline evaluation filters out bad ideas. The online test makes the final call.
Anatomy of an experiment
An A/B experiment splits users into groups and gives each group a different version of the feed.
- Control is the group that keeps the current ranking.
- Treatment is the group that gets the change, such as a new comment weight in the score or a new diversity rule.
- The unit of randomization is the thing being assigned. For feeds it is almost always the user, not the request or the post. If one person saw both versions in the same session, the feed would feel inconsistent, and their reactions would blur together.
- Random assignment is what makes the comparison fair. If the groups differ only by chance, then a difference in outcomes can be credited to the change.
Platforms usually assign users by hashing. The hash of the user ID and the experiment name decides the group. The same user always lands in the same group, and no assignment table is needed.
import hashlib
def assign(user_id: str, experiment: str, treatment_share: float = 0.5) -> str:
"""Deterministically place a user in 'control' or 'treatment'."""
key = f"{experiment}:{user_id}".encode()
bucket = int(hashlib.sha256(key).hexdigest(), 16) % 10_000
return "treatment" if bucket < treatment_share * 10_000 else "control"
for uid in ["u1", "u2", "u3", "u4"]:
print(uid, assign(uid, "comment-weight-v2"))Including the experiment name in the hash matters. Without it, the same users would always be in the treatment group of every experiment, and results from different tests would be correlated.
Choosing metrics
A feed change affects many things at once, so teams decide on their metrics before the test starts. They typically use three kinds.
| Metric type | Purpose | Example |
|---|---|---|
| Primary (success) | The outcome the change is meant to improve | Meaningful interactions per user per day |
| Guardrail | Things that must not get worse | Hide and report rate, app crashes, feed load time |
| Diagnostic | Explain why a result happened | Share of impressions from followed accounts, author diversity |
Guardrails matter because of the goals discussed earlier in the course. A change that raises clicks by pushing sensational posts may also raise hides and reports. If you only watched clicks, you would ship it. A guardrail on hide rate catches the harm.
Short-term proxies and long-term goals
What a company wants is usually long-term: people who still find the product valuable months from now. Experiments run for days or weeks, so they measure proxies, such as session counts, time spent, or survey answers about whether a feed felt worthwhile. A proxy can move in the wrong direction relative to the real goal. A more addictive feed can raise time spent today and lead to churn later.
To check this, teams keep a holdout: a small group of users who never receive a set of launched changes. Comparing the holdout with everyone else months later shows whether the accumulated short-term wins really produced long-term value.
Reading the result
Suppose treatment users average 5.20 interactions a day and control users average 5.10. Is that a real effect or noise? Individual users vary a lot, so two random groups would differ somewhat even with no change at all.
Three ideas help here.
- The standard error measures how much a group average would wobble from sample to sample. It shrinks as groups get larger.
- A confidence interval is a range of plausible values for the true effect. A 95% interval that excludes zero is the usual bar for calling a result statistically significant.
- A p-value is the probability of seeing a difference at least this large if the change actually did nothing. A small p-value, commonly below 0.05, suggests the difference is not just chance.
import math
import random
from statistics import mean, variance
def compare(control, treatment):
"""Difference in means with a 95% confidence interval and two-sided p-value."""
se = math.sqrt(variance(control) / len(control)
+ variance(treatment) / len(treatment))
diff = mean(treatment) - mean(control)
z = diff / se
p_value = math.erfc(abs(z) / math.sqrt(2))
return diff, (diff - 1.96 * se, diff + 1.96 * se), p_value
rng = random.Random(7)
control = [rng.gauss(5.10, 3.0) for _ in range(20_000)]
treatment = [rng.gauss(5.25, 3.0) for _ in range(20_000)]
diff, (low, high), p = compare(control, treatment)
print(f"diff={diff:.3f} 95% CI=({low:.3f}, {high:.3f}) p={p:.4f}")This uses a z-test, which is reasonable here because feed experiments have thousands of users per group. The simulated data has a true lift of 0.15, so the interval should usually sit above zero. The exact numbers depend on the random seed.
A small p-value does not mean the effect is large. With millions of users, a 0.1% change can be statistically significant and still not worth shipping. Read the size of the interval, not only whether it excludes zero.
Sample size and power
Power is the chance that an experiment detects a real effect of a given size. Before launching, teams estimate how many users they need. Small effects need many more users than large ones. Roughly, halving the effect you want to detect requires about four times as many users. Running a test that is too small is a common way to learn nothing.
Common ways experiments go wrong
Sample ratio mismatch
If you planned a 50/50 split and one group ends up with noticeably more users, something is broken. A logging bug, a crash in one version, or a filter applied after assignment can all cause this. This is called a sample ratio mismatch, and it means the groups are no longer comparable. Teams check for it before reading any metric.
import math
def srm_p_value(n_control: int, n_treatment: int) -> float:
"""Chi-square test (1 degree of freedom) against an expected 50/50 split."""
total = n_control + n_treatment
expected = total / 2
chi2 = ((n_control - expected) ** 2 + (n_treatment - expected) ** 2) / expected
return math.erfc(math.sqrt(chi2 / 2))
print(srm_p_value(50_200, 49_800)) # plausible split
print(srm_p_value(52_000, 48_000)) # suspicious splitA very small p-value, often below 0.001 for this check, means the split is almost certainly not chance, so investigate before trusting the results.
Peeking and multiple comparisons
Checking results every day and stopping when the p-value dips below 0.05 inflates false positives. Random noise wanders across the line often enough to fool you. Fix the duration in advance, or use methods built for continuous monitoring.
The same problem arises when you look at 40 metrics and 10 user segments. Some will look significant by luck. Name one primary metric up front, and treat surprises in other metrics as leads to test again.
Novelty and primacy effects
Users often react strongly to anything new, so a treatment can look good in week one and fade. The opposite also happens. People used to the old feed may engage less with a better one until they adapt. Running long enough to see the effect settle, and plotting it by day, guards against both.
Interference between users
Standard A/B analysis assumes one user's group does not affect another's outcome. Social platforms break this. If treatment users post more, control users who follow them see more content too. A creator in the treatment group gets more reach, which changes what their followers in the control group experience. This interference, also called a network effect, usually biases the measured effect toward zero.
Teams respond in several ways:
- Randomize by cluster, such as a community or region, so connected users share a group.
- Run marketplace-style tests for creator-facing changes, since a post only has one audience.
- Compare against a holdout over longer periods.
Experiments and feedback loops
Earlier chapters described feedback loops, where today's engagement shapes tomorrow's training data. Experiments interact with this. Treatment users generate data that may later train the model for everyone. The control group's data stops looking like normal traffic if the treatment changes what gets shown. When a model learns from the very engagement it influences, an experiment run for two weeks can understate the shift the model produces over months. This is another reason for long-running holdouts.
Connecting to user controls
Experiments average over many people, so they can hide differences between groups. A feed change that helps heavy users may hurt new users or small creators. Teams therefore split results by segment, such as new versus established users, and check for harm in any one of them. This is also why controls, like choosing a chronological view or marking posts as "not interested", matter: they let individuals correct for what the average result missed. The next chapter looks at those controls and at transparency.
Exercise
A team tests a feed change with a 50/50 split. After a week, treatment has 51,000 users and control has 49,000. Treatment shows a significant lift in comments per user. Should they trust the result? What would you check first, and what is one possible cause?
Show answer
Not yet. Check for a sample ratio mismatch first. A 51,000 to 49,000 split differs from the planned 50/50 by more than chance would normally allow at this size, so the groups may not be comparable. Possible causes include a logging bug that drops events for one version, a crash that stops treatment users from being counted, or a filter applied after assignment. Fix the cause and rerun, or correct the analysis, before reading the comments metric.
Exercise
An experiment raises time spent by 2% over two weeks, and the daily plot shows the lift is 5% in the first days and 1% by the end. The hide rate guardrail is flat. Name the likely effect and one way to learn the real long-term impact.
Show answer
This looks like a novelty effect: the lift fades as users get used to the change. To learn the long-term impact, extend the test until the daily effect stabilizes and keep a long-running holdout group that never gets the change, then compare it with launched users months later.