Part II β The Shield Β· Lesson 4.4
A/B Testing
In one lineShip two versions to real users, measure one metric, and let the data decide.
Where you've seen itNetflix showing different artwork for the same title. Same content, different thumbnail, measurably different play rate.
Diagram
THE SPLIT β assignment must be sticky and server-decided
incoming user
β
βΌ
ββββββββββββββββββββ hash(userId + experimentId) % 100
β assignment β β deterministic: same user, same bucket,
ββββββββββ¬ββββββββββ every session, every device
β
βββββββ΄ββββββ
βΌ βΌ
ββββββββ ββββββββ
β A β β B β
β 50% β β 50% β
β old β β new β
ββββ¬ββββ ββββ¬ββββ
β β
βΌ βΌ
exposure event fired once, on RENDER β not on assignment
β β
ββββββ¬ββββββ
βΌ
ββββββββββββββββ
β metric funnelβ view β click β add to cart β purchase
ββββββββββββββββ pick ONE primary metric before you startFRONTEND FAILURE MODES
β assign in the client different bucket per device/session
β flicker (CSS swap) user sees A, then B β biases the result
β log exposure on assignment counts users who never saw the variant
β 6 experiments, same surface interaction effects, unreadable result
β stop when it looks good peeking inflates false positivesHow it works
- Assign server-side or at the edge, keyed on a stable user id, and send the variant with the document.
- Render the variant on first paint. Client-side swapping causes flicker, which itself changes behaviour.
- Fire an exposure event when the variant is actually rendered, not when the flag was read.
- Pick one primary metric and a guardrail metric (e.g. conversion up, but page latency and error rate must not regress).
- Fix the duration in advance β full weekly cycles β and don't stop early because the numbers look nice.
Trade-offs
| A/B test when | Don't when |
|---|---|
| The change is measurable and reversible | It's a bug fix or a legal requirement |
| You have enough traffic for significance | Sample size gives 3-week runtimes |
| The decision is genuinely contested | The answer is already obvious |
Feature flags vs experiments: the same delivery mechanism, different intent. A flag controls release (kill switch, gradual rollout); an experiment measures effect. Reuse the infrastructure, keep the vocabulary separate β and delete both once the decision is made.
Interview angle
"How do you A/B test without hurting performance?"
- Decide at the edge so the variant ships in the HTML β no flicker, no extra round trip, no layout shift.
- Keep the payload as one small config object, not two bundles; lazy-load only genuinely divergent code.
- Add latency and error rate as guardrail metrics, so a winning variant that slows the page still loses.
Recap
- Sticky, deterministic, server-side assignment; render on first paint.
- Log exposure on render, not on assignment.
- One primary metric, one guardrail, a fixed duration, and no peeking.