skip to content

How would you run Thompson sampling on a news feed where articles arrive and expire daily?

level: principalimportance: nice to knowfreq 28%

answer

  1. the rule does not care how many arms
  2. new arm, wide posterior, free exploration
  3. count how many arms are live
  4. clicks land after the impression
  5. a flat prior is the wrong prior here

basics

~20 s

Thompson sampling handles arms coming and going without modification: each request draws over whatever arms are live, and a new arm's wide posterior earns it exploration. The real problems are cold-start priors, delayed clicks, and exploration swamping exploitation.

solid answer

~50 s

The rule itself is indifferent to a churning arm set — each request draws once per live arm and serves the argmax, so a newly published article is explored automatically because its posterior is wide, and an expired one simply leaves the draw set. Three things break at scale. Arm count: with hundreds of near-identical fresh posteriors a newcomer wins roughly one draw in K, so almost all traffic goes to exploration and the sampler never exploits — bound the pool with a cheap pre-filter. Cold start: a flat prior is the wrong prior, since you know how articles in a section perform; fit it from comparable historical articles. Delayed clicks: if you update only when a reward lands, the sampler re-serves an arm whose evidence is still in flight — record the impression immediately as a provisional non-click, or update in batches.

go deeper

for a junior

Know that a newly added arm starts with a wide posterior and therefore gets explored automatically, and that a retired arm simply stops being included in the draw. No special mechanism is required.

for a middle

Explain why arm count matters: with K near-identical fresh posteriors each newcomer wins about one draw in K, so a large live pool means almost all traffic goes to exploration. Be able to describe the delayed-reward problem in mechanical terms.

for a senior

Show you have operated something like this — provisional updates or batching for delayed clicks, priors fitted from comparable historical articles, caps on how fast an arm's share may grow, and monitoring served shares rather than only rewards.

for a principal

Own the architectural call. Decide where the bandit sits relative to retrieval, whether per-item allocation is worth it at all given article lifetimes and traffic per arm, how much of the learning belongs in population-level priors, and what guardrails let an automated allocator run the feed unattended.

## The rule needs no modification Start with what does *not* break. Thompson sampling defines a per-request procedure: draw one number from each live arm's posterior, serve the argmax. Nothing in that procedure assumes a fixed arm set. Publish a new article and it joins the draw with its prior; expire an old one and it drops out. No special-casing, no forced-exploration branch, no cold-start rule bolted on top — a new arm gets traffic precisely because its posterior is wide and therefore plausibly best. That property is a genuine reason to reach for this rule in a churning environment. Everything hard is around the edges. ## Failure one: exploration swamps exploitation With K live arms whose posteriors are all near the prior, each wins about one draw in K. If ten articles are live, that is fine — 10% of traffic goes to any given newcomer and the pool resolves within an hour. If five hundred are live and a hundred turn over daily, the arithmetic collapses: nearly all traffic is spent on arms nobody has any evidence about, and the well-performing known arms are crowded out. The sampler is behaving correctly and the outcome is terrible. The fix is upstream of the sampler. Bound the candidate pool: retrieve a small shortlist by some cheap heuristic — recency, section, editorial priority, a coarse model score — and run the sampler only over that shortlist. The bandit is a *ranker of a handful of finalists*, not a mechanism for exploring an unbounded catalogue. An interviewer is often probing exactly for the recognition that arm count, not the rule, is the binding constraint. ## Failure two: the flat prior is a lie Giving a brand-new article a uniform prior says you believe its click rate could plausibly be 80%. You do not believe that. You have thousands of past articles and you know their rates cluster tightly — say most of them between 1% and 6%. Encoding that is the single highest-leverage change. Fit the prior for a new arm from the historical distribution of comparable articles, matched on the attributes you actually have at publication time: section, source, position, time of day. The new arm then starts centred near the population mean with a width equal to the genuine between-article variation, so it is explored in proportion to how much articles *really* differ — not in proportion to total ignorance. Two direct benefits: exploration cost per new arm drops sharply, and the arm-count problem above becomes much less acute, because a newcomer no longer routinely draws absurdly high values. The risk to name is over-confidence. If the fitted prior is too tight, a genuinely exceptional article never wins draws and is never discovered — the prior has to carry the real spread across articles, not the average article's uncertainty. ## Failure three: rewards arrive after decisions An impression is served now; the click, if it comes, lands seconds or minutes later, and a downstream conversion may take longer still. If the posterior is only updated when rewards land, then for the duration of the delay the sampler sees an arm that has served heavily but shows no evidence, keeps a wide posterior, and keeps serving it. At high throughput that means thousands of impressions committed to an arm on the strength of nothing. Two standard remedies. Provisionally record the impression as a non-reward at serve time and correct it when the click lands — this makes the sampler pessimistic during the delay window, which is the safe direction. Or batch: freeze the allocation, serve for a fixed interval longer than the reward delay, then update everything at once. Batching is coarser but far simpler to reason about and to operate. ## Failure four: the horizon per arm is tiny Adaptive allocation earns its keep by exploiting for a long time after a short exploration phase. An article that expires in 24 hours may accumulate only a few thousand impressions, which for a one-point gap is nowhere near enough for posteriors to separate. Per-arm, the sampler spends most of the article's life still exploring, and the regret saving is small. The answer is to stop treating each article as an isolated arm. Share strength across arms: pool at the level of section, source or template, so evidence from one article informs the prior of the next. The individual arm's short life then rides on a slowly-learned population structure rather than starting from scratch every time. ## Operational judgment to voice - **Retire cleanly.** An expired article leaves the draw set immediately, but keep its accumulated posterior as an input to the population prior — that is where its long-term value lies. - **Bound allocation velocity.** A rule that can commit most of the feed to one article within minutes turns a tracking glitch into a visible incident. Cap how fast any arm's share may grow. - **Monitor served shares, not just rewards.** The diagnostic that catches all four failures above is the distribution of traffic across arms over time: exploration swamping shows as a flat share curve, over-confident priors show as newcomers never appearing, and delayed rewards show as an arm's share spiking before any evidence exists. - **Know when the answer is no.** If the pool is enormous, lifetimes are short and per-arm traffic is thin, per-item adaptive allocation is the wrong tool and the leverage lies in the retrieval and prior-fitting layers instead. ## The compact answer The rule survives churn untouched; what needs engineering is the number of live arms, the prior a new arm starts from, the delay between serving and learning, and the fact that a one-day article never lives long enough to be exploited.

  • What breaks first as the number of live arms grows into the hundreds?
    Exploitation. Each fresh arm wins roughly one draw in K, so with hundreds of near-identical new posteriors almost all traffic goes to arms with no evidence, and the known-good arms are crowded out. The fix sits upstream: pre-filter to a shortlist and run the sampler over a handful of finalists rather than the whole catalogue.
  • What prior would you give a brand-new article?
    Not a flat one — that asserts an 80% click rate is as plausible as 3%. Fit it from the historical rate distribution of comparable articles, matched on what you know at publication: section, source, slot, time of day. The arm then starts near the population mean with a width equal to genuine between-article variation.
  • How do you handle clicks that land minutes after the impression?
    Do not let the sampler see served traffic as evidence-free. Either record each impression immediately as a provisional non-click and correct it when the click arrives, which makes the sampler pessimistic during the delay window, or freeze the allocation and update in batches longer than the delay. Otherwise it re-serves an arm whose evidence is still in flight.
  • When would you say adaptive per-article allocation is the wrong tool here?
    When the pool is enormous, lifetimes are short and per-arm traffic is thin. An article that sees a few thousand impressions before expiring never leaves the exploration phase, so there is nothing to exploit. The leverage then lives in retrieval and in fitting good population-level priors, not in the allocation rule.

saying these in an interview costs you the question

  • Assumes new arms need forced traffic on top of the sampling rule
  • Gives every new article a flat prior no matter how many launch
  • Ignores the delay between serving an impression and the click landing
  • Keeps expired articles eligible to be served
  • Runs the sampler over the whole catalogue with no pre-filter

context