From CTR Prediction to Sequential Feed Ranking with RL
Machine LearningModel answerLast updated
Design a sequential feed-ranking system for long-term retention: choose bandit vs MDP, evaluate offline with doubly robust estimators and overlap checks, and design rewards and A/B guardrails.
Context
You work on the data science team of a large social platform. The current feed ranker is a supervised model that scores each item by its predicted click probability. Leadership wants to replace it with a reinforcement-learning approach that ranks items throughout a session and is optimized for how likely users are to keep coming back, not for immediate clicks.
What you need to answer
-
Choosing the formulation. Contrast a (contextual) multi-armed bandit with a Markov decision process for this problem. User tastes and mood can shift while a single session unfolds. Which formulation fits better, and why?
-
Offline evaluation. The new policy will be trained on logged data from the existing system. Describe how you would use a doubly robust estimator to judge the new policy before it reaches users. What diagnostics would you run to confirm that the old (logging) policy covers the behavior of the new (target) policy well enough?
-
Reward and safety. Return visits are a delayed and sparse signal at the session level. How would you build a reward that balances immediate engagement against long-term retention? Then name two concrete guardrail metrics you would monitor during the online experiment to make sure the new policy does not hurt user experience.
State your assumptions, discuss trade-offs, and point out where each approach is likely to break.
Hints
Hint 1
Ask whether an item shown now can change what the user does or feels later in the same session. If so, which framework models that dependence explicitly, and what does the other one ignore?
Hint 2
A doubly robust estimator combines a model-based prediction with an importance-weighted correction of that model's residual. Think about which quantities must be logged at serving time, and how you would measure whether the importance weights are well behaved (tails, effective sample size, horizon length).
Hint 3
For a sparse delayed outcome, consider training a model that predicts return probability from the session-end state and using changes in it as a dense shaping signal. For guardrails, think about what an optimizer could exploit (sensational content) and which user segments could be harmed while the average looks fine.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Overview
The task is to move from a one-shot click predictor to a sequential decision system while keeping the statistics honest. A strong answer chooses the formulation from the problem structure, treats overlap as something to measure, and builds a reward that cannot be gamed easily.
1. Bandit vs. MDP
| Contextual bandit | MDP | |
|---|---|---|
| State | Context only, no transitions | State evolves with past states and actions |
| Objective | Expected immediate reward | Expected discounted return |
| Credit assignment | Not needed | Required, since actions affect future rewards |
| Data and variance | Low cost | High: long horizons, compounding importance weights |
| Good fit | Independent choices (thumbnail, notification copy) | Sessions where earlier items shape later behavior |
Recommendation: model it as an MDP. What the user sees changes their state: topic fatigue, mood after negative content, expectations about feed quality, and the chance of continuing to scroll. A bandit assumes the item at slot 5 does not influence the context at slot 10, which is exactly what breaks when the goal is retention. A bandit tends to serve whatever has the highest immediate CTR, the myopic behavior we want to leave behind.
State: user embedding and long-term history, in-session history (items seen, dwell, skips, hides), session depth, and time of day. Action: the next item or the next slate of k items.
Pragmatic path. Full off-policy RL over long horizons is high-variance. A common intermediate step is a contextual bandit with a learned long-term value term: score = predicted immediate reward + γ·V̂(next state). This is essentially one-step Q-learning and is far easier to evaluate and ship.
2. Offline evaluation with doubly robust (DR)
Requirements. Logs of (state, action, reward, logging propensity μ(a|s)). Propensities must be recorded at serving time; reconstructing them later is error-prone. Let π be the target policy and Q̂(s,a) a fitted reward model.
Single-step DR:
V_DR = (1/n) Σ_i [ Σ_a π(a|s_i) Q̂(s_i,a) + w_i (r_i − Q̂(s_i,a_i)) ], w_i = π(a_i|s_i) / μ(a_i|s_i)
- The first term is the direct method: low variance, biased if Q̂ is wrong.
- The second term corrects the model using importance-weighted residuals.
- The estimate is consistent if either the propensities or Q̂ is correct, and has lower variance than plain IPS because weights multiply a residual instead of the raw reward.
Sequential version (per-decision DR), computed backward through the session:
DR_t = V̂(s_t) + ρ_t ( r_t + γ·DR_{t+1} − Q̂(s_t,a_t) ), ρ_t = π(a_t|s_t) / μ(a_t|s_t)
Practical steps
- Cross-fit Q̂ so its errors are not correlated with the residuals it is correcting.
- Control variance with self-normalized weights or clipping (for example at 10 to 50), and report how the estimate moves as the clip changes.
- For ranked slates, avoid whole-slate propensities. Use slot-level propensities with a pseudo-inverse style estimator or a position-based click model.
- Bootstrap over users, not impressions, for confidence intervals.
- Validate the pipeline on a past policy that already has an A/B result and check that it recovers the measured effect.
Overlap diagnostics
- Support: compute the share of π's mass on actions where μ(a|s) < ε. A large share means that part of the policy is unevaluable.
- Weight distribution: inspect max, p99, and tail shape; check that the mean of w under μ is about 1. A deviation signals logging bugs or support gaps.
- Effective sample size: ESS = (Σw)² / Σw². An ESS/n of a few percent means the estimate is driven by a handful of sessions.
- Horizon blow-up: plot ESS of cumulative weights Πρ_t against session depth and truncate where it collapses.
- Segments: repeat for new users, low-activity users, and locales, where overlap usually fails first.
If overlap is poor: keep π close to μ (KL penalty, behavior-regularized or conservative RL), add exploration to the logging policy going forward, or use OPE only as a coarse filter and rely on online tests.
3. Reward design and guardrails
Reward. Train a retention model R̂(s) that predicts the probability of returning within, say, 7 days from the end-of-session state; labels are observable historically. Use it for a dense reward:
r_t = Σ_k α_k · engagement_{k,t} − β · negative_t + λ · [γ·R̂(s_{t+1}) − R̂(s_t)]
- The last term is potential-based shaping, which densifies the signal without changing the optimal policy (in principle).
- Weight meaningful engagement (long dwell, shares, comments) above raw clicks, which are easy to game with clickbait.
- Sweep λ and plot the Pareto frontier of OPE-estimated CTR vs. estimated retention, then choose the operating point jointly with product leadership.
- Validate the proxy: its movement across past experiments should correlate with retention movement, not just across individual users, since correlation across users can be confounded.
Guardrails for the A/B test (pre-registered thresholds, sequential monitoring with always-valid intervals so early stopping does not inflate false positives):
- Negative feedback rate. Reports, hides, and "see less" per 1,000 impressions, plus the rate of borderline content from integrity classifiers. Roll back automatically if it rises beyond a set margin (for example +3%) with significance. Optimizers discover sensational content fast.
- Short-term retention and session health. D1/D7 return rate and median session length, broken out by segment, especially new and light users. Use a non-inferiority margin per segment so gains among heavy users cannot hide churn elsewhere.
Additional checks worth mentioning: content diversity and creator exposure, latency, and a long-running holdout to measure true retention effects.
Common mistakes
- Choosing an MDP without acknowledging the variance and evaluation cost.
- Assuming overlap instead of measuring it, or failing to log propensities.
- Bootstrapping over impressions, which understates uncertainty.
- Using a retention proxy that was never validated causally.
- Judging the experiment only on aggregate metrics.