Design an Online Comparison

After Widen the Rollout Step by Step, the team added shadow mode’s overreaches as eval cases, fixed the ones only v7 made, and reran the shadow week. This time, v7 landed within v5’s own spread. The rollout reached half the hikers by early October, and every stage stayed inside its rollback lines. That shows v7 isn’t clearly worse. It doesn’t show that v7 is better, and nobody has decided what “better” means or how much traffic would show it.

In this lesson, you’ll write a test plan for v7 against v5 before any result comes in: who gets which version, which numbers decide, and when. Then you’ll check the setup with a test where nothing changes. Start with who goes on which side.

Split by Hiker, Not by Request

An online comparison, or A/B test, sends real users to two versions at once and compares what they do. Hikers assigned to v7 carry its risk, so it’s only for versions that passed the offline evals, as v7 did.

The unit of the split is the hiker, which the bucket from Put a New Version Behind a Flag already gives you. A conversation re-sends its history on every turn, so a version picked per request would mix versions within most conversations and leave a repeat unattributed to either version.

Counting per hiker needs one more field. A bucket holds about 1 in 100 hikers, and the hiker ID would tie answers to a person. So log a per-test pseudonym, a keyed hash of the ID like tag() from Redact Before You Record, with a key that exists only for this test. Save experiment.js:

Language: JavaScript Filename: experiment.js
import { createHmac } from "node:crypto";

export function pseudonym(hiker) {
  const key = process.env.TEST_KEY;
  if (!key) throw new Error("TEST_KEY is missing");
  if (!hiker) return undefined;
  return createHmac("sha256", key)
    .update(hiker).digest("hex").slice(0, 16);
}

Add a long random TEST_KEY to .env. In server.js, call pseudonym("check") once after the imports, so a missing key stops the server. In flag(), set res.locals.pseudonym = pseudonym(hiker);. In timer(), add pseudonym to the log line. Traces keep only the bucket.

Anyone with the key can test a guessed ID against a pseudonym, so pseudonyms fall under the 30-day retention limit from Decide What Traces Keep.

End a test in this order: save the per-side results, remove the pseudonym("check") call, the res.locals.pseudonym assignment in flag(), and the log field, and restart, so nothing writes pseudonyms anymore. Only then delete TEST_KEY and rewrite server.log without pseudonym. Log with npm start | tee -a server.log, or use Tee-Object -Append in PowerShell, so restarts keep earlier lines.

Choose the Numbers Before You Start

Pick one primary metric, the number that decides, before the test starts. With a dozen numbers per version, one will favor v7 by chance.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.