Separating Automated Traffic from a Sudden Active-User Surge
Statistics & ExperimentsModel answerLast updated
Estimate how much of a short-term rise in daily active users comes from scripts rather than people, model overdispersed login counts, quantify uncertainty, and handle heavy-tailed comparisons.
Scenario
You work as a data scientist for a large consumer app. Over the last 48 hours, daily active users (DAU) rose by about 20% relative to normal. The product team thinks the jump may come from automated scripts, such as scrapers or CI test runners, rather than real growth in human usage.
Available data
- Hourly login counts for the past 60 days.
- The user-agent string for every login event.
- A per-user flag showing whether the user passed a "human-only" step, such as a CAPTCHA or a UI interaction that needs realistic latency.
Questions
- Describe a statistical framework to estimate the share of automated versus human traffic during the surge. Which distribution would you use for the login counts, given that their variance is larger than their mean?
- How would you quantify the uncertainty in your estimate of the automated-to-human ratio?
- Suppose automated accounts have heavy-tailed activity. Why might a standard two-sample t-test be a poor way to compare average activity between suspected automated and verified human accounts, and what would you use instead?
Follow-up to address
Suppose you write daily logins as Y = p * Bot + (1 - p) * Human, with the human part assumed Poisson, yet the data show much more variance than a Poisson allows. What would you change?
Hints
Hint 1
Separate two questions: how many logins exceed the expected baseline (an aggregate, time-series question), and which users are automated (a classification or composition question). Use independent methods for each and compare.
Hint 2
Poisson forces variance to equal the mean. Think about a Poisson model whose rate itself is random (Gamma-distributed), and about covariates such as hour of day and day of week that the baseline must account for.
Hint 3
The human-only flag is imperfect: some humans skip it and some bots pass it. If you know its pass rate for humans and for bots, the observed pass rate during the surge is a linear function of the bot share that you can invert.
Hint 4
For uncertainty, ask what is correlated: events within a user, and hours within a day. Resample at the level of those clusters or blocks, and build the interval on a scale where the ratio is stable.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing
There are two separate quantities here, and a strong answer keeps them apart:
- Aggregate excess: how many logins exceed what we would expect from humans alone.
- Composition: which users or sessions are automated.
Before modeling, rule out non-bot explanations briefly: a logging or instrumentation change, a deploy, a marketing campaign or holiday, and a change in how DAU is defined. A useful sanity check is engagement per active user. A real human surge tends to keep it roughly flat, whereas automated traffic dilutes it.
1. Baseline model for overdispersed counts
A Poisson model has Var = mean, which is too restrictive for traffic that varies by hour, weekday, and unobserved user mix. Use a Negative Binomial (Poisson-Gamma) GLM:
- Y_t ~ NB(mu_t, k), with Var(Y_t) = mu_t + mu_t^2 / k
- log mu_t = intercept + hour-of-day effects + day-of-week effects + trend
As k grows, this collapses to Poisson. Fit it on the roughly 56 pre-surge days, then forecast the counterfactual human counts for the 48 surge hours.
Aggregate estimate:
- Excess = sum over surge hours of (Y_t - mu_hat_t)
- p_agg = Excess / sum of Y_t
A 20% DAU increase implies about 0.2 / 1.2, or roughly 17%, of surge traffic is excess. This assumes the excess is entirely non-human, so treat it as an upper bound if some of the lift is organic.
Alternatives worth naming: quasi-Poisson (Var = phi * mu), a Poisson-lognormal model with an hourly random effect, or a variance-stabilizing transform (square root or Anscombe for Poisson-like data, log(Y + c) when variance scales like mu^2).
Correcting the follow-up. The expression Y = p*Bot + (1-p)*Human conflates two ideas. Counts add (Y = Y_H + Y_B), while individual users form a mixture (each is a bot with probability p). If the human component is overdispersed, replace the Poisson with a Negative Binomial rather than transforming a Poisson.
2. Composition via a latent class model
Give each user i a latent label Z_i in {bot, human} with P(bot) = p. Useful features:
- User-agent tokens (headless browsers, scripting libraries, CI runners, impossible or outdated strings).
- Regularity of inter-login gaps: the coefficient of variation is near zero for scripts.
- Hour-of-day entropy: scripts are often flat across 24 hours, humans follow a diurnal curve.
- Per-user login count, modeled as NB with class-specific means.
- The human-only flag.
Fit by EM, assuming conditional independence given class:
- E-step: r_i = p f_B(x_i) / [p f_B(x_i) + (1-p) f_H(x_i)]
- M-step: p = mean(r_i), then update class parameters.
A Bayesian version uses a Beta prior on p and MCMC or variational inference. Guard against label switching by constraining the bot class, for example to have lower timing entropy.
Treat the flag as a noisy label. Let s = P(flag | human), estimated from the pre-surge period when p is about 0, and e = P(flag | bot), small and estimated from known bot traffic. With observed surge flag rate f:
f = (1 - p) s + p e, so p_hat = (s - f) / (s - e)
Example: s = 0.90, e = 0.05, f = 0.75 gives p_hat = 0.15 / 0.85, about 0.176. That agrees with the aggregate excess of about 0.167.
Triangulate: the NB excess, the flag inversion, and the EM mixture are three largely independent estimates. Agreement among them is the strongest evidence you can offer.
3. Uncertainty for the bot-to-human ratio
The target is r = p / (1 - p).
- Bootstrap with the right dependence. Resample users (cluster bootstrap) for composition, since events within a user are correlated. For the time-series part, use a block bootstrap (for example 24-hour blocks) or simulate from the NB predictive distribution. Re-run the entire pipeline, including EM, on every replicate.
- Delta method. Var(r_hat) is approximately Var(p_hat) / (1 - p_hat)^4. For the flag estimator, Var(p_hat) is approximately Var(f_hat) / (s - e)^2, plus error from estimating s and e. Because r explodes as p approaches 1, build the interval on logit(p) and transform back.
- Bayesian. Compute r for each posterior draw of p and read off a credible interval.
Report two sources of uncertainty: forecast uncertainty in the baseline (use a prediction interval, not a confidence interval for the mean) and classification uncertainty in the mixture.
4. Why a t-test fails with heavy tails
A t-test compares means and leans on the CLT for the standard error. With heavy-tailed bot activity:
- A few extreme accounts dominate both mean and variance, so the standard error is unstable and coverage is poor.
- With a Pareto tail index at or below 2, variance is infinite and the CLT does not apply.
- Power drops, because inflated variance hides shifts in the bulk of the distribution.
- The data are discrete, skewed, and have very unequal variances across groups.
Better options:
- Mann-Whitney / Wilcoxon rank-sum: robust, but it tests stochastic dominance, P(X_bot > X_human), not a difference in means.
- Permutation test on a robust statistic such as the median or a 10% trimmed mean.
- Bootstrap CI for differences in medians, trimmed means, or upper quantiles, clustered by user.
- Model-based: NB regression on per-user counts, a log transform if the data look lognormal, or quantile regression.
Pick the estimand first: a typical account (median) versus total load on the system (sum or mean) lead to different tests.
Common mistakes
- Using Poisson standard errors on overdispersed data, giving intervals that are far too narrow.
- Ignoring seasonality, so every weekday peak looks like an anomaly.
- Treating the human-only flag as ground truth instead of correcting for its pass rates.
- Running an i.i.d. bootstrap over events or hours, ignoring autocorrelation and within-user correlation.
- Reading Mann-Whitney as a test of means.
- Ignoring label switching in the mixture model.