You own change verification for a multi-tenant compute platform: about 3,000 tenant resource pools, jobs inside a pool share one compute quota, and the platform serves roughly 100 million requests a day. A performance-only optimization sits behind a flag, and you need to answer one question: how much did it change job duration?
Randomizing by request gives the most samples, but it does not work here. Inside one pool, quota that treatment saves is consumed by control, and customers will not accept a pipeline that is fast for half its queries and slow for the other half. The unit has to move up to the resource pool, and that costs three things:
Requirements: detect a 1% regression within two weeks; A/A false positive rate at the nominal 5%; a consistent customer experience within any time window; automatic stop when a guardrail trips.
graph TD
C["Change + flag metadata
stateful? changes results? shared resource?"] --> P{"Design selector"}
P --> F["Fixed assignment
stratified randomization"]
P --> S["Switchback
randomized schedule"]
F --> E["Flag evaluation
pinned at request start"]
S --> E
E --> X[("Exposure log")]
X --> G["Aggregate by randomization unit"]
H[("Pre-experiment baseline")] --> G
G --> A["Analysis
CUPED · paired differences · randomization test"]
AA["A/A replay gate"] -.-> A
A --> V["Verdict + guardrail auto-stop"]
The design selector reads flag metadata and decides which experiment designs this change is allowed to use. Flag evaluation reads the value at request start and pins it, so a request belongs to one arm for its whole life. The exposure log records which arm each request was in, and every analysis depends on it. Aggregation always happens at the randomization unit and is joined with the pre-experiment baseline. The A/A replay gate uses historical data to verify the false positive rate of a given design-plus-analysis pair before any real experiment may use it.
One-line trade-off: a finer unit gives more samples, but if the two arms share a resource the estimate is biased; a coarser unit is cleaner and has less power.
An A/B test assumes that a unit's outcome depends only on its own assignment (SUTVA). A shared resource pool breaks that assumption, and the bias can go either way. If treatment frees quota, control speeds up too and the effect is underestimated. If treatment uses more resources, control is squeezed, the gap is overestimated, and the "gain" vanishes at full rollout. Two rules follow: the randomization unit is never smaller than the resource-sharing boundary, and the analysis unit equals the randomization unit. Assigning by pool and then treating each request as an independent sample overstates the sample size by orders of magnitude.
| Randomization unit | What you get | What you give up |
|---|---|---|
| Request | Most samples, an answer in hours | Interference within the pool; inconsistent experience for one customer |
| Project / user | Consistent customer experience | Projects in the same pool still compete for one quota, so interference remains |
| Resource pool | Interference is closed inside the unit | Only a few thousand units; heavy tail and heterogeneity dominate the variance |
| Cluster / region | Even cross-pool shared layers are closed | Only tens of units; a fixed split detects almost nothing |
# How much power a coarse unit really costs (pseudo-code)
def n_eff(n_requests, m_per_unit, icc):
return n_requests / (1 + (m_per_unit - 1) * icc) # design effect
def mde(sigma, n_per_group, z_alpha=1.96, z_power=0.84):
return (z_alpha + z_power) * sigma * (2 / n_per_group) ** 0.5
n_eff(1e8, m_per_unit=33_000, icc=0.2) # ~15,000: 100M requests are nowhere near 100M independent samples
mde(sigma=0.5, n_per_group=1500) # ~0.051: a fixed split by pool only detects a 5% change
One-line trade-off: it changes neither assignment nor customer experience, so it is nearly free; but it only reduces variance, does not fix bias, and how much it helps depends entirely on how well the metric correlates with its own past.
Large pools were already slow and small pools were already fast, and that difference has nothing to do with the experiment. CUPED removes it using each unit's value of the same metric before the experiment, X:
Y' = Y − θ·(X − mean(X)) θ = Cov(X, Y) / Var(X) Var(Y') = (1 − ρ²)·Var(Y)
Because assignment is random, X has the same expectation in both arms, so subtracting it introduces no bias. ρ, the correlation between X and Y, decides how much you save:
| ρ | Remaining variance | Equivalent sample multiplier |
|---|---|---|
| 0.5 | 75% | 1.3× |
| 0.7 | 51% | 2.0× |
| 0.9 | 19% | 5.3× |
| 0.95 | 10% | 10× |
Four rules. The covariate must come entirely from before the experiment, or it will subtract the treatment effect along with the noise. Take logs or winsorize heavy-tailed metrics first. Use the delta method for the variance of ratio metrics. Put new units with no history in a stratum of their own. At assignment time, also stratify by size so large pools are balanced across arms.
import numpy as np
def cuped(y, x, treated):
"""y: metric during the experiment; x: same metric, same unit, before it; treated: bool array"""
theta = np.cov(x, y)[0, 1] / np.var(x, ddof=1) # estimate θ on both arms pooled
y_adj = y - theta * (x - x.mean())
t, c = y_adj[treated], y_adj[~treated]
delta = t.mean() - c.mean()
se = np.sqrt(t.var(ddof=1) / len(t) + c.var(ddof=1) / len(c))
return delta, se
# heavy-tailed metrics: first y, x = np.log(y), np.log(x)
One-line trade-off: it removes heterogeneity and within-pool interference at the same time; the price is carryover across time, and it only works for changes that can be flipped back and forth.
What gets randomized changes from "which units" to "which time windows". The same pool runs with the flag on for some windows and off for others, and differences between pools cancel in the subtraction. Five design decisions:
| Pool | D1 | D2 | D3 | D4 | D5 | D6 |
|---|---|---|---|---|---|---|
| pool-a | on | off | off | on | on | off |
| pool-b | off | on | off | on | on | off |
| pool-c | on | off | on | off | off | on |
In analysis each pool yields one number: the mean of its on windows minus the mean of its off windows. Then run a paired test or a randomization test across pools.
import hashlib, numpy as np
def arm(exp_id, pool_id, day): # pair adjacent days, randomize within the pair
pair, pos = divmod(day, 2)
h = hashlib.sha256(f"{exp_id}:{pool_id}:{pair}".encode()).digest()[0] & 1
return "on" if h == pos else "off" # each pair has exactly one on day and one off day
def analyze(rows, burn_in_h=2): # rows: (pool, day, hour, arm, value)
by_pool = {}
for pool, day, hour, a, v in rows:
if hour < burn_in_h: continue # discard the burn-in after a switch
by_pool.setdefault(pool, {"on": [], "off": []})[a].append(v)
d = np.array([np.mean(g["on"]) - np.mean(g["off"]) for g in by_pool.values()])
return d.mean(), d.std(ddof=1) / np.sqrt(len(d)) # analysis unit = resource pool
One-line trade-off: one site-wide rule is easy to explain but makes most changes pay for the constraints of a few; choosing the design by change type gives more power but depends on trustworthy metadata.
| Change type | Allowed design | Why |
|---|---|---|
| Stateful (storage format, metadata writes) | Fixed assignment, forward only | Cannot be flipped back and forth |
| Changes results or semantics | Fixed assignment, shadow comparison first | The same request returning different results on different days is an incident |
| Same results, performance only | Switchback, unit is the resource pool | Each unit is its own control, highest power |
| Affects shared-resource efficiency | Unit no smaller than the resource pool | Anything finer contaminates the other arm |
Metadata will be filled in wrong, so you also need a gate that does not depend on the change: A/A replay. Take historical data, assign it randomly under the same design a thousand times with no real change, and the share of runs with p < 0.05 should sit near 5%. If it is clearly higher, the analysis unit or the variance estimate is wrong.
def choose_design(flag):
if flag.stateful: return Fixed(unit="pool", reversible=False)
if flag.changes_results: return Fixed(unit="project", shadow_first=True)
if flag.expected_effect_small:
return Switchback(unit="pool", window="1d")
return Fixed(unit="pool", stratify="size", cuped=True)
def aa_gate(history, design, analyze, runs=1000, alpha=0.05):
fp = sum(analyze(design.assign(history, seed=s)).p < alpha for s in range(runs))
return abs(fp / runs - alpha) < 0.015 # refuse the design if it drifts from nominal
Fixed split: 1,500 per arm gives a standard error of 0.5 × √(2/1500) ≈ 1.8%, and the minimum detectable effect is about 2.8 standard errors, or 5%. With CUPED at ρ = 0.9, multiply by √0.19 to get about 2.2%; reaching 1% needs ρ ≈ 0.98. Switchback: assume a day-to-day coefficient of variation of 0.1 within one pool and two weeks with 7 days on and 7 off. The standard deviation of one pool's difference is about 0.1 × √(2/7) ≈ 5.3%, the standard error across 3,000 pools is about 0.1%, and the detectable effect is about 0.3%. Even with only 500 pools it reaches roughly 0.7%. The gap comes from one fact: day-to-day variation within a pool is far smaller than the differences between pools. All of these inputs are assumptions; the real values have to be measured from historical data and A/A replay.
Not with daily windows. Carryover is longer than the window, so what you measure in an on window is still the off state, the effect is diluted, and no amount of burn-in is enough. There are two ways out. Stretch the window to several times the carryover (two-week windows, say, which leaves only a handful of windows in several months and no power). Or accept that this is a slow-variable change and go back to a fixed split with CUPED, trading a longer experiment for power. How long carryover lasts can itself be measured: turn the change fully on and watch how long the metric takes to settle. Bojinov et al. also give a data-driven procedure for identifying the order of carryover.
A fixed split is close to hopeless: 15 against 15, and whichever arm draws the largest pool decides the outcome. CUPED cannot rescue a unit count that small. Switchback is the main route: each pool is its own control, and 30 pools × 28 days gives 840 pool-days. Do not lean on a normal approximation for inference; use a randomization test. Regenerate a few thousand schedules under the same rule and see where the real difference ranks, which gives an exact p-value. Run for longer, and accept that only larger effects are detectable. This is also why sensitive large customers are better served by shadow execution: they carry no risk and you still get paired data.
That is 2,000 tests a day, so about 100 come out "significant" with no real regression at all. If there are only one or two real regressions a day, the chance that a given alert is real is 1% to 2%, which is exactly the base-rate problem from Day 51: a low per-test false positive rate does not make an alert trustworthy. The remedies are the same. Lower the per-test false positive rate (stricter guardrail thresholds, multiple-comparison correction). Shrink the decision domain (only look at metrics the metadata says could be affected). Chain an independent layer of evidence (a regression counts only if it reproduces in a second window).
A chaos experiment injects a fault with a large effect over a short time, and the goal is to falsify the hypothesis that steady state holds. A comparison lasting tens of minutes is enough, sample size is not the bottleneck, and blast radius is. A performance change is the opposite: the effect is around one percent, the risk is low, and the bottleneck is power. So the first spends its effort on automatic abort and radius control, the second on variance reduction. What they share is the question "were the two groups the same to begin with?" Chaos experiments answer it with a control group from the same time window and the same routing rule; this issue answers it with stratification, CUPED and self-control.