Turning Expected Profit into Keyword Bids Under a Daily Budget
Machine LearningModel answerLast updated
Design a system that converts predicted business value of a search-ad click into a bid, paces spend against a budget, handles delayed conversions, and proves incremental profit.
An online home-goods retailer buys sponsored placements on a search engine. Each time a shopper runs a query, the platform runs an auction, and the retailer may submit a bid for its ad.
Describe how you would build a bidding system that:
- Converts the business value of each ad opportunity into a bid.
- Stays within a campaign budget over the day or campaign period.
- Copes with purchases that are reported days after the click.
- Is evaluated in a way that shows whether it actually improves the business.
The auction mechanics, available features, attribution rules, and budget figures are not given. Begin by stating the assumptions you will make, and do not assume that the amount you bid is the amount you will be charged.
Points worth clarifying up front:
- Is the goal incremental contribution profit, orders, new customers, or revenue subject to a return target?
- Is pricing per click, per impression, or per conversion, and what controls does the platform expose (bid, budget, targeting, bid modifiers)?
- What are the conversion delay, the budget size, stock availability, and any geographic or time-of-day restrictions?
Expected: a structured design covering value estimation, the bid formula, pacing, feedback delay, and evaluation, with trade-offs and common pitfalls.
Hints
Hint 1
Split the problem into two layers: a prediction layer (click probability, conversion probability, order value, margin) and an optimization layer that turns those predictions into a bid under a budget.
Hint 2
Think about what the bid should be relative to the value of a click when the budget is binding, and what a pacing multiplier does to it. Also recall how a second-price style auction changes the incentive to shade the bid.
Hint 3
For evaluation, ask what would have happened without the ad. Consider geo or query-level holdouts, and remember that recent clicks have incomplete conversion labels.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Assumptions to state first
- Objective: maximize incremental contribution profit (margin minus ad cost, minus returns) within a daily budget. A ROAS or cost-per-acquisition target is a fallback if profit is hard to measure.
- Pricing: cost per click. The platform runs a generalized second-price style auction with a quality score, so the charged price is typically below the bid and depends on competitors. I will not assume pay-what-you-bid, and I will log the actual charged price.
- Controls: we set a bid per keyword/query-cluster/audience/device, and can apply multipliers. The platform enforces a hard daily cap.
- Attribution: last-click with a 30-day window. Conversions arrive with a long-tailed delay, with most inside 1-3 days.
2. Prediction layer
For each opportunity (query, product or category, device, location, time, user signals):
- pCTR: probability of a click, if bidding is per impression or if we need to forecast spend.
- pCVR: probability a click leads to purchase within the attribution window.
- E[margin | purchase]: expected order contribution margin after COGS, shipping, and expected returns. This is often more important than revenue, since high-revenue items can be low margin.
- Incrementality factor i in [0,1]: the fraction of conversions that would not have happened without the ad. Branded queries have low i (the shopper would likely have arrived organically); generic queries have higher i.
Models: gradient-boosted trees or a small neural net, with calibrated outputs (isotonic or Platt calibration), since the bid is a product of probabilities and miscalibration directly turns into overbidding. Use hierarchical backoff or shrinkage for sparse keywords so that a keyword with 3 clicks does not get a wild estimate.
Value of a click:
V = pCVR × E[margin] × i
3. From value to bid
With a per-click second-price auction and no budget constraint, bidding truthfully (bid = V) is optimal, since you pay less than your bid when you win and never want to win at a price above V.
With a binding budget, the optimal policy is to bid below value using a Lagrange multiplier on spend:
bid = V / (1 + λ)
where λ ≥ 0 is the shadow price of budget. If the budget is slack, λ = 0 and we bid V. If it is tight, λ rises and we only win the opportunities with the highest value-to-cost ratio. Equivalently, we choose a ROI threshold and only buy clicks above it.
Practical points:
- Apply guardrails: a min and max bid, a cap on change per update, and a floor on position or impression share only if there is a business reason.
- Add an exploration premium for new or low-data keywords (a small, capped bid uplift or Thompson sampling on pCVR) so the model can learn them. Budget exploration explicitly, for example 5% of spend.
- Account for inventory: set the bid to zero or lower it when a product is out of stock or has slow delivery.
4. Budget pacing
Goal: spend the budget evenly in proportion to the traffic that is valuable, not run out by noon.
- Forecast the expected traffic and win rate by hour from history (with day-of-week and seasonality).
- Run a feedback controller (PID-style) that compares actual cumulative spend to the target spend curve every few minutes and adjusts λ, or equivalently a pacing multiplier on bids between 0 and 1.
- Cap the step size to avoid oscillation, and handle spikes (a promotion, a viral product) by allowing the target curve to be reshaped toward high-value hours rather than being flat.
- Monitor for under-delivery as well. Leftover budget with a positive-ROI marginal click is lost profit.
5. Delayed conversions
Training labels for recent clicks are incomplete, so naive training makes the model believe recent traffic converts less.
- Use a delay model: estimate the distribution of time-to-conversion and weight or correct the labels (importance weighting, or a survival-style model that jointly predicts conversion and delay).
- Alternatively, train only on matured data (older than the window) and add a fast-signal model on early proxies (add-to-cart, session depth) to fill the gap.
- For pacing, use predicted value of recent clicks, not realized conversions, so the controller does not react to missing labels.
- Monitor calibration on matured cohorts, and retrain regularly.
6. Evaluation
Offline:
- Calibration (log loss, reliability curves) and ranking quality (AUC) for each predictor.
- Counterfactual replay of the bidding policy is biased because we only observe outcomes for auctions we won. Use inverse propensity weighting with a modeled win probability, and treat the result as directional.
Online (the real test):
- Geo experiments or query-split holdouts: randomize regions or keyword groups into the new policy versus the control policy, with matched pre-period behavior. User-level randomization is usually not possible in a search auction.
- For the incrementality factor, run ad-off holdouts (for example, pause ads in a random set of geos) and measure total orders, not just attributed orders.
- Primary metric: incremental contribution profit net of ad cost. Secondary: spend utilization, ROAS, new-customer rate, impression share on high-value queries. Guardrails: budget overspend, CPC spikes, out-of-stock clicks.
- Run long enough to cover the conversion delay, and use variance reduction (CUPED with pre-period data) given the small number of geos.
7. Common mistakes
- Optimizing on attributed revenue or ROAS, which rewards buying clicks that would have converted anyway (especially branded terms).
- Using revenue rather than margin, or ignoring returns.
- Bidding V without any budget shading when the budget is tight, which exhausts spend on mediocre clicks early.
- Treating the bid as the cost and mixing up bid with charged price in spend forecasts.
- Training on immature labels, which biases pCVR downward for fresh traffic.
- Uncalibrated probabilities, and over-trusting sparse keywords.
- Declaring success from an A/B on attributed conversions without a holdout.
8. Trade-offs and extensions
- Simpler: rule-based bids from historical ROAS per keyword. Cheap and robust, but slow to react and noisy on the long tail.
- More complex: a contextual bandit or reinforcement learning controller that learns the bid-response curve directly. It handles competition shifts better, but needs careful safe-exploration and simulation.
- Follow-up topics to expect: how to handle cold-start products, how to detect when competitors change behavior, and how to allocate budget across campaigns by equalizing marginal return.