Bell Statistics

What is a switchback test?

A switchback test randomises time periods rather than users, applying one condition to everyone during each interval and alternating between them. It is the design for marketplaces and shared systems, where users in different arms would otherwise affect each other.

Also called
switchback experiment, time-based randomization, temporal randomisation, alternating treatment design
Allon Korem

Written by Allon Korem

Chief Executive Officer

Last updated

In plain English

User-level randomisation assumes one user's assignment does not affect another's outcome. In a marketplace that assumption fails immediately. If a pricing algorithm is shown to half the riders, they compete with the other half for the same drivers, and a change that wins by capturing supply looks good while creating nothing. The arms are not independent, so the comparison is not measuring what it claims.

A switchback test removes the problem by making the randomisation unit time. The entire system runs condition A for thirty minutes, then condition B for thirty minutes, then A again — with the order randomised rather than strictly alternating. During any interval everyone experiences the same condition, so there is no cross-arm competition to distort things. The comparison is between periods rather than between people.

The price is a dramatic reduction in sample size, and it is the fact that governs everything about the design. A week of thirty-minute intervals is 336 units, not the hundreds of thousands a user-randomised test would have. Statistical power comes from the number of switches, so switchback tests are structurally underpowered relative to A/B tests and need to run for weeks to detect effects that a normal test would resolve in days.

Choosing the interval length is the main design decision and it is a genuine trade. Short intervals give more units and therefore more power, and they increase carryover — the effect of one period bleeding into the next, since a driver positioned by condition A is still positioned at the start of condition B. Long intervals reduce carryover and leave you with very few units. The usual approach is to set the interval from how long the system takes to settle after a change, then discard a burn-in window at the start of each period from the analysis.

Two further points matter in practice. Time is not exchangeable — Friday evening is not Tuesday morning — so the randomisation must be balanced across time-of-day and day-of-week, and the analysis should account for those as covariates. And because periods adjacent in time are correlated, the standard error needs to reflect that: treating 336 intervals as independent observations overstates precision, and a block bootstrap or a model with autocorrelated errors is the standard correction.

The formula

The unit is an interval rather than a user, and every consequence for power and for variance estimation follows from that.

Number of units
units = duration / interval length

A week of 30-minute intervals gives 336. This is the sample size, not the number of users.

The comparison
effect = mean( Y | periods assigned A ) − mean( Y | periods assigned B )

A difference between time periods. Balance the assignment across day-of-week and hour, or the comparison is confounded with time.

Burn-in
discard the first w minutes of each interval

The system is still settling from the previous condition. w is set by how long the market takes to re-equilibrate.

Correlated periods
use a block bootstrap or autocorrelation-robust standard errors

Adjacent intervals are not independent, so naive standard errors are too small — see bootstrap.

Worked example

A delivery marketplace tests a new courier-matching algorithm. User-level randomisation is impossible because both arms would draw from the same courier pool. They run a switchback over three weeks with one-hour intervals, discarding the first ten minutes of each as burn-in.

Duration
21 days
Interval
1 hour → 504 units
Burn-in discarded
10 minutes per interval (17% of data)
Mean delivery time, condition A
31.4 minutes
Mean delivery time, condition B
29.8 minutes
Naive SE / block bootstrap SE
0.31 / 0.74 minutes

The new algorithm cuts delivery time by 1.6 minutes. With correct standard errors that is p = 0.031, not the p < 0.001 the naive calculation claims.

The two standard errors differ by a factor of 2.4, and only the larger one is defensible. Adjacent hours are strongly correlated — demand, weather and courier supply all persist across an hour boundary — so treating 504 intervals as 504 independent observations claims far more information than three weeks of operation contains. The result survives the correction here, which is fortunate rather than guaranteed; a smaller effect would have crossed from significant to not. Two design notes worth carrying forward. The 17% of data discarded as burn-in is a real cost and the right trade: without it, every interval's first minutes are contaminated by the previous condition, biasing the comparison towards no effect. And three weeks was necessary rather than cautious — at 504 units this design has roughly the power of a 500-observation experiment, which is why switchbacks are slow even on high-volume systems.

Common misconceptions

A switchback test is just an A/B test with time as the unit.
Structurally yes, and the consequences are large. The sample size collapses from users to intervals, adjacent units are correlated rather than independent, and time itself is a confounder that must be balanced. Each of those changes how the test is designed and how the standard error is computed.
Shorter intervals are better because they give more data points.
They give more units and more carryover, since the system has less time to settle before the next switch. Below the time the market takes to re-equilibrate, additional intervals are increasingly contaminated by the previous condition and the effect is biased towards zero. The interval should be set by system dynamics, not by the desire for a larger n.
With millions of orders the switchback has plenty of statistical power.
Power comes from the number of switches, not the number of orders within them. A three-week test at one-hour intervals has about 500 units regardless of whether each contains a hundred orders or a hundred thousand. More volume per interval reduces within-interval noise and does not increase the effective sample size.

Frequently asked questions

How do I choose the interval length?
From how long your system takes to settle after a change. If courier positioning re-equilibrates in about ten minutes, an hour gives a clean fifty minutes of measurement per interval; a fifteen-minute interval would be mostly burn-in. Estimate the settling time from historical data on how quickly the relevant metric stabilises after a known operational change, then pick an interval several times longer.
When do I need a switchback rather than a normal A/B test?
When users in different arms would compete for or affect a shared resource — marketplace supply, delivery capacity, inventory, an auction, a shared queue. The signature is that treating one user changes another user's experience, which breaks the independence a user-randomised test assumes. If the change is confined to what an individual sees and does, an ordinary A/B test is fine and far more powerful.
Why do switchback tests need special standard errors?
Because adjacent time periods are correlated — demand, weather, staffing and everything else persists across interval boundaries — so the intervals are not independent observations. Naive standard errors treat them as though they were and come out too small, often by a factor of two or more. A block bootstrap that resamples contiguous runs of intervals, or a model with autocorrelation-robust errors, is the standard fix.

Related terms

  • A/A test

    Testing nothing against nothing to check the instrument — and it should be significant about five per cent of the time.

  • A/B/n test

    Several complete alternatives against one control — and each extra arm costs twice: less traffic and another chance to be wrong.

  • Multivariate test

    Every combination, so interactions are visible — at roughly four times the traffic per effect you want to see.

  • Randomization

    The one mechanism that makes a comparison causal — and the four ways it silently fails.

  • Cluster randomization

    Assign the group, not the person — the remedy for interference, paid for in statistical power.

  • Feature flag

    The switch experiments run on — and the reason a flag that changes mid-test quietly invalidates the result.

Calculate it

  • Paired t-test

    Before-and-after or matched pairs — size the study on the difference SD, then test it.

  • Two-sample t-test

    Compare the average of two independent groups — plan the sample size, then test the result.

Knowing the term is the easy part

Applying it to a live measurement problem is the part that goes wrong. If you are designing an experiment, reading a result you do not trust, or trying to work out what your marketing actually caused, that is the work we do.

References