Attach Active Ranking Model Version to Feed Impressions with merge_asof
Last updated: November 29, 2026
Quick Overview
You have a log of News Feed ranking model deployments per region (deploy_ts, region, model_version) and a log of feed impressions (impression_ts, region, user_id, clicked). Tag each impression with the model version live in its region at that moment and compute CTR per version.
Meta
November 29, 20260
0
0 solved
You have a log of News Feed ranking model deployments per region (deploy_ts, region, model_version) and a log of feed impressions (impression_ts, region, user_id, clicked). Tag each impression with the model version live in its region at that moment and compute CTR per version.
Meta ranking teams constantly need to attribute metrics to the model that was serving, and deploys roll out by region at different times. This screen question checks whether a candidate reaches for an as-of join rather than a cross join and handles impressions that happened before any deploy.
What the Interviewer Expects
- Identify this as an as-of (point-in-time) join, not an equality join
- Sort both frames by the time key as merge_asof requires
- Use the by parameter to match within region
- Use direction='backward' so the latest deploy at or before the impression wins
- Handle impressions before the first deploy (NaN version) explicitly
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you handle a gradual rollout where only 10 percent of traffic got the new model?
- How would you do the same join in Spark or Presto?
- Why could CTR per version be confounded even with a correct join?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
deploys(deploy_ts, region, model_version) and impressions(impression_ts, region, user_id, clicked). A deploy at exactly the impression time counts as live. Impressions before any deploy in their r...
Approach
pd.merge_asof(impr, deploys, left_on='impression_ts', right_on='deploy_ts', by='region', direction='backward') finds, for each impression, the latest deploy in the same region at or before it. It re...