Why wait for a winner? Optimizing Black Friday sales with Multi-Armed Bandits
Context
Context: Black Friday is around the corner, and the marketing team wants to test different promo messages to maximize conversions/purchases. Marketing lead comes to me: “A/B test is great, but Black Friday is short! I can't afford to waste 50% of my traffic on a losing variant. Is there a way we can learn and optimize on the fly?”
Well, this is where Multi-Armed Bandits (MAB) come into play!
The MAB is a sequential decision-making problem that balances exploration vs. exploitation to maximize cumulative rewards.
- Exploration: Try different options to learn which performs best.
- Exploitation: Allocate more resources to the best-performing option based on current knowledge.
Approaches to Solving the Multi-Armed Bandit Problem
Methods
- Pure Greedy: Always select the best-performing arm (exploitation only).
- \(\varepsilon\)-Greedy: Randomly explore with probability \(\varepsilon\) and exploit the best-performing arm with probability \(1-\varepsilon\).
- Upper Confidence Bound (UCB): Select the arm with the highest (up-to-date) reward plus an exploration bonus (rewarding the under-represented arm).
- Bayesian UCB: Select the arm with the highest (up-to-date) posterior reward plus an uncertainty bonus (from standard deviations).
- Thompson Sampling: Sample from each arm's (up-to-date) probability distribution to balance exploration and exploitation.
2. The Black Friday Example
For the Black Friday promo, suppose we run some test for the first 20 mins with the following observed conversion rates:
| Promo | Message | Observed CVR |
|---|---|---|
| A | \(\$10\) off \(\$30\) | 8% |
| B | 30% off everything | 7% |
Here's how each proposed method works in practice:
- Pure Greedy: Always show Promo A because it has a higher conversion rate (8%).
- \(\varepsilon\)-Greedy: Suppose \(\varepsilon = 10\%\), show Promo A 90% of the time and randomly/uniformly choose between A and B the remaining 10% of the time.
- Algorithms for Traditional UCB, Bayesian UCB, and Thompson Sampling are illustrated below.
| Promotion | Conversions | Non-Conversions | Total Visitors (\(n_i=a_i+b_i\)) |
|---|---|---|---|
| A | \(a_A\) | \(b_A\) | \(n_A\) |
| B | \(a_B\) | \(b_B\) | \(n_B\) |
- The following table summarizes how each algorithm selects the promotion for the next customer.
| Traditional UCB | Bayesian UCB | Thompson Sampling | |
|---|---|---|---|
| Exploitation (Reward) | Observed CVR: \(\hat{p}_i=\frac{a_i}{n_i}\) | Posterior mean: \(\mu_i=\frac{a_i+1}{n_i+2}\) | \(\tilde{p}_i\sim\text{Beta}(a_i+1,b_i+1)\) |
| Exploration (Bonus) | \(\sqrt{\frac{c\ln N}{n_i}}\) | \(c\sigma_i\) | |
| Arm Selection | Deterministic | Deterministic | Stochastic |
| Decision Rule | Select the arm with the highest \(\hat{p}_i+\sqrt{\frac{c\ln N}{n_i}}\) | Select the arm with the highest \(\mu_i+c\sigma_i\) | Select the arm with the highest \(\tilde{p}_i\) |
Where:
- \(i\in\{A,B\}\): Promotion index.
- \(N=n_A+n_B\): Total visitors across both promotions.
- \(\sigma_i=\sqrt{\frac{(a_i+1)(b_i+1)}{(n_i+2)^2(n_i+3)}}\): Posterior standard deviation.
- \(c\): Hyperparameter controlling the degree of exploration.
- In this practice, I applied \(c = 3\) for both methods.
- \(\tilde{p}_i\): Randomly sampled CVR from the posterior Beta distribution.
Intutions:
- (Traditional UCB) \(\sqrt{\frac{c\ln N}{n_i}}\): Given the same total number of visitors (\(N\)), the less-visited arm receives a larger exploration bonus, encouraging exploration.
- (Bayesian UCB) \(\sigma_i^2={\frac{(a_i+1)(b_i+1)}{(n_i+2)^2(n_i+3)}}=\frac{\mu_i(1-\mu_i)}{n_i+3}\): Holding the posterior mean constant (\(\mu_i\), same rewards), more visits lead to smaller posterior variance (thus less bonus).
- (Thompson Sampling): The distribution curve naturally balances exploitation and exploration: a higher mean favors performing arms, while a larger variance gives the less precise/certain arm a chance to be explored.
- The interactive tool below helps build intuition.
Interactive Thompson Sampling demo
● Promo A ● Promo B · Dashed lines show the sampled rates.
| Metric | Promo A | Promo B |
|---|
Simulation
Suppose the true CVRs of Promo A and B are 8% and 10% respectively, and their initial observed CVRs are 8% and 7% as indicated above.
In this reproducible simulation example, I:
- Apply the five proposed methods.
- Compare traffic allocation, cumulative conversions, and cumulative regret of each method.
- Note: This is a single simulation run and results can vary by seed.
For the code and full simulation, see the GitHub notebook.
Performance summary
| Strategy | Traffic to A | Traffic to B | Conversions | Overall CVR |
|---|---|---|---|---|
| Pure Greedy | 100.00% | 0.00% | 1,582 | 7.91% |
| Epsilon-Greedy | 50.28% | 49.72% | 1,715 | 8.58% |
| Traditional UCB | 34.28% | 65.72% | 1,821 | 9.10% |
| Bayesian UCB | 1.26% | 98.74% | 1,955 | 9.78% |
| Thompson Sampling | 2.43% | 97.57% | 1,935 | 9.68% |
Traffic allocation
Cumulative conversions
Cumulative regret
Conclusions
- Pure Greedy: Without exploration, the algorithm gets stuck with the initially better-performing Promo A, resulting the worst campaign results.
- Epsilon-Greedy: Random exploration allows the algorithm to eventually discover the better-performing arm. However, the choices prior were sub-optimal and depending on when the sub-optimal arm is identified, the consequent reward vary.
- Traditional UCB: This algorithm exhibits the most volatile traffic allocation. While it successfully identifies Promo B as the better option, persistent exploration reduces cumulative rewards.
- Note: The UCB exploration bonus can take various functional forms. Here, I use a generalized UCB method with a tunable exploration coefficient for simple demonstration.
- Bayesian UCB and Thompson Sampling: Both leverage posterior distributions for uncertainty, enabling more efficient exploration and exploitation. Results for the two methods are comparable in this exercise.
- Note: Similar to generalized UCB, the coefficient in Bayesian UCB is tunable. In the appendix, I demonstrate how different values of this hyperparameter affect traffic allocation and thus the promo result.
- Note: Thompson Sampling is not tied to the Beta distribution. Its defining feature is sampling a plausible model from the posterior before choosing an action.
| Type of Problem | Example Model |
|---|---|
| Binary Outcome | Beta |
| Continuous Variable | Gaussian |
| Complex neural networks | Approximate posterior / ensembles |
- Overall: Bayesian UCB and Thompson Sampling generate significant more conversions than Pure Greedy. This demonstrates the business value of adaptive traffic allocation, particularly for high opportunity cost and short-duration campaigns such as Black Friday.
- Cold Start: The same process applies without prior information, yielding comparable results.
- Conclude MAB?: Bandit experiment concludes not through a traditional statistical significance test (e.g., p-value < 0.05), but through a Bayesian stopping rule based on the potential value remaining (PVR). The intuition is simple: stop experimenting when the potential benefit of further exploration becomes sufficiently small. For implementation details, see Scott's Multi-Armed Bandit Experiments in the Online Service Economy.
Advanced Topics
- Contextual Bandits: The idea is simple. In our Black Friday example, we try to pick a single winner that maximizes overall performance. However, customers spending exactly \$30 may prefer "\$10 off \$30" over "30% off." Different users may respond differently to the same offer.
Contextual Bandits introduce personalization into the algo by selecting the best arm based on each user's context rather than choosing a single winner for everyone.
- Reinforcement Learning: Multi-Armed Bandit (MAB) is a simplified form of Reinforcement Learning (RL). Both learn through trial and error and balance exploration and exploitation to maximize cumulative rewards.