Updated 24 October 2026
Multi-armed bandits and exploration
Learning what works while serving users: the explore-exploit trade-off, epsilon-greedy, upper confidence bounds and Thompson sampling, contextual bandits, bandits versus A/B tests, uses in ranking, notifications, pricing and creative selection, logging for off-policy evaluation, and pitfalls.
Try it yourself, in a playground:A/B test peekingMulti-armed banditsAd auctions
A recommendation system that only shows what it already knows works well never learns about new items. An A/B test that splits traffic evenly for two weeks keeps showing the losing variant to half the users. Multi-armed bandits balance learning (exploration) with using what has been learned (exploitation), shifting traffic toward better options as evidence accumulates. They come up in feed, recommendation and notification designs as the answer to cold start and "how do you choose between options automatically?".
The explore-exploit trade-off
Each option (an "arm": a thumbnail, a headline, a notification time, a candidate item) has an unknown reward rate (click, watch, purchase). Every time you choose:
- Exploit: pick the option with the best estimate so far.
- Explore: try something less certain, which might be better.
Pure exploitation gets stuck on early winners; pure exploration wastes traffic. Bandit algorithms manage the balance.
Common algorithms
| Algorithm | How it chooses | Notes |
|---|---|---|
| Epsilon-greedy | best option most of the time, a random one with probability ε | simple; explores blindly; ε often decays over time |
| Upper confidence bound (UCB) | option with the highest optimistic estimate (mean plus uncertainty bonus) | explores options with few observations; deterministic |
| Thompson sampling | sample a plausible reward rate for each option from its posterior, pick the highest sample | explores in proportion to the chance of being best; strong in practice |
For click-style rewards, Thompson sampling with Beta distributions is a few lines of code: keep counts of successes and failures per arm and sample.
Contextual bandits
Rewards often depend on context: user, device, time of day, item features. Contextual bandits learn a model mapping context to expected reward per action and add exploration around it (for example, sampling from model uncertainty, or epsilon exploration). They sit between simple bandits and full recommendation models, and are widely used for personalised choices like which artwork to show for a title. See Design Netflix.
Bandits versus A/B tests
| A/B test | Bandit | |
|---|---|---|
| Goal | measure the effect precisely | maximise reward during learning |
| Traffic split | fixed | adapts toward winners |
| Statistical clarity | high, simple to analyse | harder; biased estimates without care |
| Regret (lost reward while learning) | higher | lower |
| Best for | product decisions, long-term metrics, guardrails | many options, short-lived content, continuous optimisation |
Use A/B tests for decisions you need to understand and defend (a new ranking model, a pricing change), and bandits for ongoing optimisation among many options (headlines, thumbnails, notification templates). See feature flags and A/B testing.
Where they appear
- Cold start: give new items or creators some exposure to learn their quality. See recommendation systems.
- Feed ranking exploration: reserve a small share of slots for uncertain candidates to avoid feedback loops. See Design a News Feed.
- Notifications: choose send time, template and channel per user. See Design a Notification System.
- Dating and marketplaces: give new profiles or providers visibility while learning. See Design Tinder.
- Ads and creatives: choose among ad creatives. See ad serving and auctions.
System design
- Decision service: given context, returns an action and the probability with which it was chosen (the propensity).
- Logging: record context, action, propensity, and later the reward, joined by a decision id. Rewards may arrive late (a purchase days later), so joins use windows. See windowing and watermarks.
- Updating: simple bandits update counters in near real time (in a fast store); contextual models retrain periodically from logs. See feature stores and ML serving.
- Off-policy evaluation: with logged propensities, you can estimate how a new policy would have performed on past data (inverse propensity scoring) before deploying it.
Pitfalls
- Non-stationarity: popularity changes; use decay or sliding windows so old data does not dominate.
- Delayed and noisy rewards: optimising clicks may hurt long-term satisfaction; choose rewards carefully and keep guardrail metrics.
- Too little exploration after the algorithm becomes confident; keep a floor.
- Peeking at results from a bandit as if it were an A/B test gives biased effect sizes.
- Fairness: exploration and exploitation affect creators and sellers; monitor exposure.
In the interview
"For thumbnails we run a Thompson sampling bandit per title and user segment, so traffic shifts to the best artwork within hours; decisions log their propensities so we can evaluate new policies offline. For the ranking model change itself we use a standard A/B test with guardrails." Brief and precise is enough.
Checklist
- Explore-exploit trade-off stated; exploration share bounded.
- Thompson sampling or UCB for simple choices; contextual bandits for personalised ones.
- Bandits for continuous optimisation, A/B tests for measured decisions.
- Propensities and rewards logged for evaluation.
- Decay for changing environments; carefully chosen rewards and guardrails.
Questions people ask
What is a multi-armed bandit?
A multi-armed bandit is an algorithm that chooses among options (arms) with unknown reward rates while balancing learning about them (exploration) with using what has been learned (exploitation). It shifts traffic toward better options as evidence accumulates, instead of splitting traffic evenly for a fixed period. Arms can be thumbnails, headlines, notification times or candidate items, and the reward is a click, a watch or a purchase.
What is the difference between a multi-armed bandit and an A/B test?
An A/B test keeps a fixed traffic split to measure an effect precisely, while a bandit shifts traffic toward winners to maximise reward during learning. A/B tests are simple to analyse but have higher regret (reward lost while learning); bandits have lower regret but give biased estimates without care. Use A/B tests for decisions you must understand and defend, such as a new ranking model, and bandits for ongoing optimisation among many options, such as headlines or thumbnails.
What is the explore-exploit trade-off?
The explore-exploit trade-off is the choice, on every decision, between picking the option with the best estimate so far (exploit) and trying a less certain option that might be better (explore). Pure exploitation gets stuck on early winners, and pure exploration wastes traffic. Bandit algorithms manage the balance, and a floor on exploration stops them from exploring too little once they become confident.
What is the difference between epsilon-greedy, UCB and Thompson sampling?
Epsilon-greedy picks the best option most of the time and a random one with probability ε, so it is simple but explores blindly. Upper confidence bound (UCB) deterministically picks the option with the highest optimistic estimate, the mean plus an uncertainty bonus, so options with few observations get tried. Thompson sampling samples a plausible reward rate for each option from its posterior and picks the highest, exploring in proportion to each option's chance of being best; it is strong in practice.
What is a contextual bandit?
A contextual bandit learns a model that maps context (user, device, time of day, item features) to the expected reward of each action, and adds exploration around it, for example by sampling from model uncertainty or with epsilon exploration. It exists because rewards often depend on context. Contextual bandits sit between simple bandits and full recommendation models, and are widely used for personalised choices such as which artwork to show for a title.
How do you evaluate a bandit policy offline?
Log each decision's context, action and propensity (the probability with which the action was chosen), and later its reward, joined by a decision id. With logged propensities, inverse propensity scoring estimates how a new policy would have performed on past data before it is deployed. Rewards can arrive late, such as a purchase days after the decision, so the joins use windows.