Beyond Traditional A/B Testing: Why Bayesian Bandits Win in Paywall Optimization
Understand Beta-Bernoulli Thompson Sampling, cumulative regret, delayed feedback, holdouts, and a reproducible 30-day paywall simulation.
Key Takeaways
- Thompson Sampling adaptively allocates traffic by sampling each arm’s posterior, which can reduce cumulative opportunity cost when an inferior paywall would otherwise keep receiving a fixed test share.
- Bandits optimize observed reward during allocation; they do not automatically provide unbiased long-term lift estimates, handle delayed revenue, or eliminate holdouts and inferential analysis.
- ONLang applies Thompson Sampling to human-approved paywall compositions, using a factored Bayesian model rather than independent arms, with a 10% default holdout outside the bandit and expected-loss promotion rules, without generating production code.
A fixed A/B test is designed to learn with a predetermined allocation. A multi-armed bandit is designed to balance learning with earning while the experiment runs. For a paywall, that difference matters because every impression assigned to a weak variant has an immediate opportunity cost.
“Bandits win” is nevertheless conditional. They can reduce cumulative regret under suitable assumptions; they do not guarantee higher final revenue, valid naive confidence intervals, or immunity to changing acquisition quality. The right architecture often combines adaptive optimization with a persistent control and fixed-window analysis.
The opportunity cost of a fixed 50/50 split
Suppose two paywalls have stable, immediate binary purchase probabilities of 4% and 6%. A fixed 50/50 test continues sending half of eligible traffic to the 4% arm until its planned horizon. That allocation can be appropriate for estimation, but it deliberately incurs a cost to learn.
A p-value answers a particular question about incompatibility between observed data and a null model. It does not tell you how much reward was forgone during data collection. Peeking repeatedly and stopping when a threshold looks attractive can also invalidate naive fixed-horizon inference.
A bandit changes the objective: allocate more impressions to arms likely to be best while retaining exploration. The key metric is cumulative regret, commonly defined as the expected reward from always choosing the best fixed arm minus the expected reward of the arms the policy actually chose.
This does not make fixed tests wasteful in every context. If you need a precise treatment effect, delayed retention estimate, or regulatory-grade readout, a randomized fixed design may be worth its opportunity cost.
Beta-Bernoulli posteriors without notation fog
For a binary conversion outcome, start an arm with a Beta(α, β) prior. After observing s successes and f failures, conjugacy gives:
posterior = Beta(α + s, β + f)
A common neutral starting point is Beta(1, 1), but that is a modeling choice, not a law. A prior can encode historical evidence if the population and measurement are comparable. Strong priors can also delay adaptation when conditions change.
Thompson Sampling draws one random sample from each arm’s posterior for the next decision, then selects the arm with the largest sample. Uncertain arms occasionally win the draw, producing exploration. As evidence concentrates, likely better arms receive more traffic.
For product managers: each paywall has a probability distribution over its conversion rate, not just a point estimate. The system samples plausible rates and acts on the most optimistic plausible arm in that round. This naturally balances “try it” with “use what works.”
See Chapelle and Li’s empirical evaluation and Agrawal and Goyal’s analysis for foundational evidence and theory. Those results do not remove app-specific assumptions.
A reproducible 30-day simulation
The following Python 3 program compares fixed 50/50 allocation with Thompson Sampling under deliberately simple assumptions: 1,000 independent impressions per day, immediate Bernoulli outcomes, stationary true rates of 4% and 6%, no repeated users, and a Beta(1, 1) prior. It uses a fixed seed so results are reproducible. These are simulated outcomes, not customer benchmarks.
from dataclasses import dataclass
import random
DAYS = 30
IMPRESSIONS_PER_DAY = 1000
TRUE_RATES = (0.04, 0.06)
SEED = 20261027
@dataclass
class BetaArm:
alpha: float = 1.0
beta: float = 1.0
def update(self, success: bool) -> None:
if success:
self.alpha += 1
else:
self.beta += 1
def sample(self, rng: random.Random) -> float:
return rng.betavariate(self.alpha, self.beta)
def run(policy: str) -> tuple[int, float]:
rng = random.Random(SEED)
arms = [BetaArm(), BetaArm()]
successes = 0
regret = 0.0
for _day in range(DAYS):
for _ in range(IMPRESSIONS_PER_DAY):
arm = rng.randrange(2) if policy == "ab" else max(
range(2), key=lambda index: arms[index].sample(rng)
)
success = rng.random() < TRUE_RATES[arm]
arms[arm].update(success)
successes += int(success)
regret += max(TRUE_RATES) - TRUE_RATES[arm]
return successes, regret
for strategy in ("ab", "thompson"):
conversions, cumulative_regret = run(strategy)
print(strategy, conversions, round(cumulative_regret, 2))
Run it multiple times with different seeds before drawing conclusions. One seed can favor either policy. Add confidence intervals across many independent simulations and compare total successes, cumulative regret, arm allocation, and final estimates.
The model’s two percentage-point gap is hypothetical. Do not confuse it with a 2% relative improvement: moving from 4% to 6% is a 50% relative increase. Real paywalls also have eligibility rules, repeated exposures, store cancellations, refunds, and subscriptions whose value arrives over time.
Why regret curves need careful interpretation
Cumulative regret under the simulation’s best-fixed-arm definition rewards policies that exploit the 6% arm early. It does not measure customer lifetime value, experimental bias, or the cost of delayed feedback. A curve that looks better after 30 days is not automatically evidence about renewals or refunds.
A/B allocation often produces more balanced arm counts, which can be useful for estimation. Thompson Sampling produces adaptive, unbalanced data. Naively applying fixed-experiment confidence intervals to that data can be misleading because assignment probabilities depend on prior outcomes.
Keep a record of propensities or use inference methods designed for adaptive experiments when a formal estimate is needed. Alternatively, run a separate fixed validation phase after optimization. The operational policy and the statistical readout should be chosen deliberately rather than conflated.
ONLang’s homepage demo uses simplified, immediate conversion feedback. It should be read as an explanatory model, not a promise of app-specific uplift or a full solution to every adaptive-inference problem. The production optimizer differs from the two-arm example: compositions are combinations of discrete variants, so it fits a factored Bayesian logistic model (main effects plus whitelisted interactions) and uses Thompson Sampling over that posterior. The holdout is analysed separately, with a Beta posterior for the uplift of the optimized cohort over it. Promotion requires the winner’s expected loss to be below 1% of the control’s rate and P(winner > control) ≥ 95% over several consecutive daily decisions, which also keeps A/A tests from crowning a winner. A person then confirms the promotion.
Delayed feedback breaks the simple loop
A paywall impression may start a seven-day trial, and the trial may convert later. If the bandit counts only immediate purchases, it optimizes a different reward from eventual paid conversion. If it waits seven days before updating, early allocation uses less information and pending outcomes accumulate.
Define the reward and maturation window before launch. ONLang lets each experiment choose conversion (the default) or paid, where trials that have not matured enter through a calibrated proxy whose calibration is shown in the report. Options include optimizing an immediate proxy while monitoring delayed paid conversion, using delayed-feedback methods, or batching updates after outcomes mature. Each has trade-offs. Do not count a trial start and its later payment as two independent successes for the same arm outcome.
Revenue rewards introduce another choice. Binary conversion treats a cheap monthly and expensive annual purchase identically. Revenue-weighted bandits need different likelihoods and expose the policy to variance, refunds, and renewal timing. A high short-term reward arm can still produce worse retention.
Monitor early cancellation, refund, renewal, support, and performance guardrails outside the immediate reward. A bandit does not understand customer harm unless that harm is represented and acted on.
Non-stationarity and candidate-set changes
The simple posterior assumes observations are generated from a stable arm-specific probability. Real conversion varies by weekday, geography, campaign, app version, price tests, and season. If acquisition quality shifts globally, all arms’ posteriors may chase an outdated average.
Segment only when sample sizes and predeclared logic support it; too many contexts fragment data. Discounted or restless bandits can address drift, but add parameters and operational complexity. A persistent control helps diagnose common shocks because it experiences the same calendar and acquisition environment.
Changing the set of generated variants mid-run also changes the experiment. Freeze a finite approved hypothesis set for a defined phase. New LLM proposals should pass validation and enter a separately versioned phase. Finite hypothesis spaces explains why this boundary matters.
Holdout groups are particularly important when the optimized allocation and external conditions change together.
Where ONLang fits
ONLang does not let the optimizer invent arbitrary UI. Developers register native components, product and legal owners constrain the hypothesis space, the validator gates every variant, and a person approves it before it receives traffic. The optimizer selects among valid compositions. Billing remains StoreKit 2, Play Billing, RevenueCat, or app-provided functions.
The CLI creates a token hypothesis, validates it, publishes it, and starts an experiment with a holdout:
onlang hypothesis create --id paywall.cta.copy --kind tokens --screen paywall \
--key cta.title --rationale "Name the outcome, not the step" \
--variant "outcome=Get my plan" --variant "trial=Try Pro free for {{trial.annual}}"
onlang lint
ONLANG_TOKEN=onl_sk_… onlang publish
ONLANG_TOKEN=onl_sk_… onlang experiment create --placement paywall --holdout 0.1 --start
ONLANG_TOKEN=onl_sk_… onlang experiment status <id>
Use the iOS guide, Android guide, or React Native guide to instrument real native impressions. Exposure logging must occur when the user actually sees the paywall, not when a candidate is prefetched.
Choose the right experiment for the decision
Use a fixed A/B test when balanced allocation and conventional estimation are central, when outcomes are delayed and precious, or when a small number of decisions requires a clean read. Use Thompson Sampling when many approved alternatives compete, feedback is timely enough, and opportunity cost during learning matters.
Use both when continuous optimization must coexist with long-term accountability: a holdout for incrementality, fixed readout windows for retention and refunds, and adaptive allocation for the eligible optimization population. Neither policy should silently change the outcome definition midstream.
Start with simulated data, then replay historical events if their assignment semantics are known. Finally, run a low-risk native hypothesis with explicit stop rules. A statistically sophisticated allocator cannot repair duplicated purchase events or contaminated control traffic.
ONLang offers full functionality for 14 days per new app, with production use and no card required at signup. Start the trial and compare the simulation’s assumptions with your actual event pipeline before enabling broader optimization.