A production model's request error rate is 2%. A canary deployment receives 5% of 1,000 queries per second (QPS). Using a one-sided test at significance level α=0.05 and power 0.8 (with zα=1.645 and zβ=0.8416), how many canary requests are needed to detect a rise in error rate to 2.5% against the baseline fleet, and how long does that take? Why does peeking repeatedly at canary metrics inflate false alarms?

ML system design, Deployment
Level L4 Advanced. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can size a canary guardrail check statistically, convert request count into wall-clock duration, and explain sequential peeking and hard circuit breakers.

Key idea

Comparing a 5% canary against a 95% baseline fleet means the baseline has 19 times as many requests, so treating the baseline rate p0=0.02 as known (a one-sample approximation) gives n=(zαp0(1−p0)+zβp1(1−p1))2(p1−p0)2≈5,233 canary requests, or about 104.7 s at 50 QPS. Repeatedly peeking with a fixed-horizon test inflates false rollbacks, so use either a fixed window or sequential testing alongside hard circuit breakers for catastrophic spikes.

Steps

  1. Set up the comparison and state the approximation: the baseline error rate is p0=0.02, the degraded canary rate to detect is p1=0.025, and the canary receives 0.05×1,000=50 QPS while the baseline receives 950 QPS (nbase=19 ncanary). In a two-proportion test, the baseline contributes only 1/19 of the variance, so we treat p0 as known and use the one-sample normal approximation (noting that keeping the 1/19 baseline variance term raises n only slightly, to about 5,490).
  2. Write the one-sample sample-size formula for one-sided level α=0.05 (zα=1.645) and power 1−β=0.8 (zβ=0.8416): n=(zαp0(1−p0)+zβp1(1−p1))2(p1−p0)2. Here 1−β=0.8 is statistical power and zα,zβ are standard normal quantiles.
  3. Compute the intermediate standard deviations: p0(1−p0)=0.02×0.98=0.0196=0.14, and p1(1−p1)=0.025×0.975=0.024375≈0.156125.
  4. Evaluate n and the wait time: the numerator inside the square is 1.645×0.14+0.8416×0.156125≈0.2303+0.131395=0.361695, whose square is 0.130823. Dividing by (0.025−0.02)2=0.0052=2.5×10−5 gives n≈5,232.9, so 5,233 canary requests. At 50 QPS, this takes 5,23350≈104.7 s (about 1 min 45 s).
  5. Explain why repeated peeking inflates false alarms: testing the cumulative canary rate every few seconds with a fixed-horizon threshold zα=1.645 gives random fluctuations many chances to cross the boundary, pushing the overall Type I error rate well above 5%. Either wait for the fixed horizon n or use an always-valid sequential test (such as alpha-spending or a mixture sequential probability ratio test).
  6. Add hard circuit-breaker limits for catastrophic failures: statistical sample sizes target subtle shifts like 2%→2.5%, whereas severe outages (for instance, error rate jumping above 10% over 100 requests or timeouts spiking) should trigger an immediate rollback without waiting for 5,233 requests.

Common mistakes

How long your answer should be

About 3–4 minutes; state the one-sample approximation, show n=5,233 and 104.7 s, then cover peeking and hard limits.

Read this

Previous in ML system design: Clicks from a ranked list are biased by display position. Under the examination hypothesis P(click∣item,pos)=P(examined∣pos)×P(relevant∣item), with position propensities [1.0,0.6,0.3] for positions 1–3, how do you show that inverse propensity weighting (IPW) gives an unbiased estimate of relevance, and what are the naive click-through rate (CTR) and the IPW estimate for an item shown 100 times at position 1 (30 clicks), 100 times at position 2 (18 clicks), and 200 times at position 3 (18 clicks)?
Next in ML system design: How would you design a spam detection system for a large messaging or email platform?