How would you implement a multi-armed bandit for real-time ad optimization?

System design balancing exploration and reward.
Use Thompson Sampling or UCB1; split low-latency inference from async updates; track regret.
Epsilon-greedy without Bayesian updates, delayed feedback, or scaling.
What's really being asked
This question evaluates whether you can translate a theoretical reinforcement learning problem into a scalable production architecture. Interviewers care about your grasp of the exploration versus exploitation trade-off, your ability to separate online inference from offline learning, and your awareness of operational realities like delayed feedback, non-stationary click-through rates, and distributed state management.
The full answer
First, algorithm selection. Name Thompson Sampling with Beta priors for binary click rewards or UCB1 for frequentist confidence bounds. Second, system architecture. Sketch a low-latency ad server that fetches arm distributions from Redis or a feature store, samples an arm in single-digit milliseconds, and logs the impression. Third, feedback loop. Show an async stream processor, perhaps Kafka to Flink, that consumes click events, updates the posterior parameters or empirical means, and writes back to the store. Fourth, exploration handling. Explain that Thompson Sampling naturally explores by drawing from the posterior, while UCB1 adds an explicit confidence bonus. Fifth, scaling and robustness. Mention sharding by user segment or campaign, handling delayed clicks with attribution windows, using uniform priors for cold-start arms, and decaying old data when ad fatigue makes rewards non-stationary.
The mistakes people make
Proposing a pure epsilon-greedy strategy without discussing why it wastes regret on obviously inferior arms. Ignoring the engineering split between synchronous serving and asynchronous learning, which would add tens of milliseconds to every ad request. Failing to address delayed feedback, meaning clicks arrive minutes after impressions and can temporarily skew reward estimates. Treating the problem as a static A/B test with occasional randomization rather than a continuous online learning loop.
What usually comes next
How do you handle non-stationarity when an ad's click-through rate decays over time? What happens if your state store fails and the serving tier loses all posterior parameters? How do you prevent a new arm from starving due to low initial samples? Can you extend this to contextual bandits using user features?
A concrete example
Imagine three ad copy variants for a sneaker campaign. Variant A has a Beta(50, 950) posterior after 1,000 impressions, variant B is Beta(5, 95), and variant C is a new arm at Beta(1, 1). At serving time, Thompson Sampling draws a random value from each Beta distribution. A usually wins because its mean is highest, but B occasionally wins when it draws above its mean, and C wins rarely because its prior is wide. When a user clicks, the async pipeline increments the alpha parameter for that variant. Over a day serving ten million requests, the system automatically shifts traffic toward A while still giving B and C enough impressions to prove whether they are actually better.
Interview question
When ad fatigue makes click-through rates non-stationary, what operational change keeps Thompson Sampling accurate?
- a.Shard the bandit by user segment to isolate stationary sub-populations.
- b.Gradually decay older impression and click data so recent observations dominate the posterior.Correct
- c.Reset all arms to uniform priors whenever aggregate campaign CTR falls below a moving average.
- d.Switch to epsilon-greedy and periodically randomize traffic to discover new optimal arms.
Why? this is the answer
Decaying old data prevents stale observations from skewing the posterior as the true reward distribution drifts over time. Switching to epsilon-greedy is a common anti-pattern because it wastes regret on obviously inferior arms rather than adapting the model to new data.
Just read this? Test yourself on what you have been reading.
Read the original → en.wikipedia.org
- #multi-armed bandit
- #reinforcement learning
- #online experimentation
- #system design
- #ads
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles