DaletGuard supports civilians affected by armed conflict through Families Beyond War. All sides, no political affiliation. About our humanitarian work

Thompson Sampling for Ad Traffic Allocation

Thompson sampling is a way to split ad traffic so that better ads earn extra views as the proof grows. Instead of a fixed fifty-fifty split, each ad gets a share that matches its real chance of leading the test. This article explains the idea in words, and it shows how DaletAds turns chances into whole-number shares for each ad. It also covers an exploration floor, which keeps every live ad in the test even when one looks far ahead. Each statement below comes from the code and its notes, and your own tests should confirm every number before use.

The wider measurement flow is described in our ad measurement and testing guide.

Illustration of puzzle, flask, A and B cards for thompson sampling
Key takeaway

Thompson sampling gives each ad a share of traffic that matches its chance of leading. A clear leader earns most of the traffic, a tie splits evenly, and a floor keeps every live ad in the test.

Why does a fixed split waste spend on a losing ad?

Also, a fixed split is simple. Two ads get half of the traffic each in a static split, from the first day to the last. However, if one ad is clearly better by day three, the other ad keeps burning budget.

In addition, an adaptive split fixes this waste. It moves traffic toward the leading arm while the test runs, as an adaptive split. As a result, fewer views go to the loser, and the regret cost of the test falls.

Moreover, the risk of an adaptive split is moving too fast. The weights are shifted only as fast as the evidence allows.

An ad that looks good on ten views may be lucky. Therefore, a good allocation rule must learn quickly and still protect against noise. Likewise, thompson sampling is a rule built for this balance.

How does thompson sampling turn the evidence into a split?

Each ad has a posterior, and each cycle makes a posterior draw from it. A posterior draw is a random sample, which is the range of rates that the data still allows. At each cycle, the rule draws one random rate from the posterior of every ad. Besides, the ad with the highest draw wins that round.

Repeat the draw many times over.

The share of rounds that an ad wins is its probability of leading. Indeed, thompson sampling then gives that same share of traffic to the ad. These shares are applied as the traffic weights. This idea is called probability matching, and it is the heart of the rule.

Notably, two cases show how thompson sampling behaves. If one ad is clearly ahead, it wins nearly every round, and it absorbs most of the traffic. If two ads are tied, each wins about half of the rounds, and the traffic splits evenly. Read our guide to Bayesian ad testing for the model behind the posteriors.

Why must a split stay adaptive and not be static?

DaletAds states this as a product rule. In fact, the allocation must not be a static fifty-fifty split. A clear leader should absorb almost all traffic, while tied arms share it evenly.

DaletAds competitor evidence records screen
For example, the competitor evidence records screen of DaletAds.

Why does a weaker ad still keep a minimum share?

Overall, a pure rule could starve an ad on early noise. A starved arm is never given a second chance. Suppose the strongest ad starts badly by chance. Importantly, it could lose all traffic, and the test would never find out.

To prevent this, DaletAds sets an exploration floor.

Also, every active ad keeps a minimum weight, which the code calls the warmup weight. The runner-up in particular keeps its arm weight above the warmup weight, so the leading arm is found quickly.

In addition, the exploration floor is a small tax. It costs a little spend on weak ads. In return, it protects the test from a wrong early verdict. Moreover, it keeps evidence flowing for every ad that is still in the race.

What does the hierarchical prior add to early rate data?

Early data is thin in most tests. With ten views, one lucky response can double a rate. Therefore, DaletAds uses a hierarchical prior, which pulls early estimates toward known base rates.

Likewise, this pull is strong at the start and weak later. A hierarchical prior is a shared belief about ad rates, and it gives a weak start a fair chance. After many samples, the data outweighs the prior. In the first few hundred views, however, the hierarchical prior keeps a lucky streak from looking like a star.

Besides, the hierarchical prior and the exploration floor serve the same purpose. Both protect thompson sampling from early noise. A shrunk estimate is calmer than a raw one. Indeed, both also fade in importance as real samples accumulate.

Why does DaletAds avoid a Top-Two variant of the rule?

A known variant, called Top-Two Thompson sampling, splits traffic between the two leading ads. With the common mixing weight of one half, a test with one champion and one challenger splits about fifty-fifty. Notably, that holds no matter how far ahead the leader is.

DaletAds rejects this behavior on purpose, and it keeps plain thompson sampling. The common case is one champion and one lone challenger, and a static split there contradicts the product rule. For that reason, the code uses the plain rule with a floor and a prior instead.

How do traffic weights become whole numbers on each cycle?

A platform needs clear numbers, not probabilities, so thompson sampling must end in traffic weights. DaletAds converts the chances into integer weights from 1 to 100. In fact, the weights sum to 100 for each cycle.

Every active ad is at or above the exploration floor. Each weight is checked against that floor. Overall, the weight table is then easy to apply and easy to audit. Anyone can read each arm weight, and anyone can check that it sums to 100.

Because the split is adaptive, the planned share of each ad changes over time. A downstream check must therefore compare observed traffic with the planned weights, and not with an equal split. Our article on sample ratio mismatch explains that check.

What should a team watch when traffic follows the evidence?

Adaptive splits change what you can read from raw counts, and thompson sampling is no exception. An ad that gets extra traffic will collect extra samples. Therefore, compare ads by their rates and probabilities, and not by totals.

Also keep the stopping rule in view. The minimum samples and the confidence bar still decide when a winner is named. Our guide to ad test sample size explains those limits. In addition, a rollback rule can cut a harmful ad, as described in ad test rollback rules.

Finally, do not treat the traffic weights as a promise. DaletAds publishes no promised lift from adaptive allocation. Measure your own results, and compare them with a plain split on a small test first.

How can a team try the idea on a small test?

Follow this short list for a first trial:

  1. Pick one low-risk element, such as a headline.
  2. Set a clear metric and a time limit.
  3. Run the test with two challengers.
  4. Watch how the weights move over several cycles.
  5. Compare the result with a plain split.

Why does thompson sampling suit live ad budgets so well?

Thompson sampling matches traffic to evidence, and thompson sampling suits live budgets. A leader earns most of the traffic, and a tie splits evenly. A floor and a prior protect against early noise. The weights stay whole numbers that anyone can audit.

DaletAds builds this rule into its experiment engine. The method also works with any toolset that lets you set weights. For a deeper treatment, read the tutorial on Thompson sampling (opens in new tab) by Russo and colleagues.

A diagram of three stacked layers, from the first at the top: Exploration floor, Hierarchical prior.

Questions and answers on this topic from the product team

What is Thompson sampling in an ad test?

It is a rule that gives each ad a share of traffic equal to its chance of leading. The chance comes from posterior draws, which are random samples from what the data says so far. Better ads earn extra traffic as proof grows.

Is the split fixed at fifty-fifty?

No. A clear leader absorbs most of the traffic, while ads that are statistically tied split it evenly. DaletAds deliberately avoids a static split, because a fixed half and half wastes spend on a losing ad.

Why does a weaker ad still get traffic?

Every active ad keeps a minimum weight, so no ad is starved by early noise. The floor keeps the runner-up learning, which helps the test find the leading arm sooner. Without it, one unlucky start could end an ad early.

What does the hierarchical prior do?

It pulls very early estimates toward known base rates. A new ad with three lucky clicks therefore does not look like a star. The pull fades as real samples build up.

What format do the traffic weights take?

The weights are whole numbers from 1 to 100 that sum to 100 for each cycle. Every active ad is at or above the floor in the traffic weights. The result is simple to apply and easy to audit.

See how DaletAds fits the providers your team uses today

Book a short meeting for a walkthrough with your own providers in mind, or join an in-person class to learn the method first.