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 and power (with and ), 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 as known (a one-sample approximation) gives canary requests, or about at . 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
- Set up the comparison and state the approximation: the baseline error rate is , the degraded canary rate to detect is , and the canary receives while the baseline receives (). In a two-proportion test, the baseline contributes only of the variance, so we treat as known and use the one-sample normal approximation (noting that keeping the baseline variance term raises only slightly, to about ).
- Write the one-sample sample-size formula for one-sided level () and power (): Here is statistical power and are standard normal quantiles.
- Compute the intermediate standard deviations: , and .
- Evaluate and the wait time: the numerator inside the square is , whose square is . Dividing by gives , so canary requests. At , this takes (about ).
- Explain why repeated peeking inflates false alarms: testing the cumulative canary rate every few seconds with a fixed-horizon threshold gives random fluctuations many chances to cross the boundary, pushing the overall Type I error rate well above . Either wait for the fixed horizon or use an always-valid sequential test (such as alpha-spending or a mixture sequential probability ratio test).
- Add hard circuit-breaker limits for catastrophic failures: statistical sample sizes target subtle shifts like , whereas severe outages (for instance, error rate jumping above over requests or timeouts spiking) should trigger an immediate rollback without waiting for requests.
Common mistakes
- Using a two-sided when the question asks for a one-sided test for an error-rate increase ().
- Dividing by the total instead of the canary's share (), which underestimates the wait time by .
- Running a fixed-horizon p-value check every second and rolling back on the first dip below , which causes frequent false alarms.
How long your answer should be
About 3–4 minutes; state the one-sample approximation, show and , 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 , with position propensities 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?