Match Client and Server Ad Impression Logs One to One
Last updated: November 29, 2026
Quick Overview
Meta logs ad impressions on the client and on the server, without a shared id. Match each client impression to at most one server impression for the same user and ad within 5 seconds, closest first, and report the unmatched rate on each side.
Meta
November 29, 20260
0
0 solved
Meta logs ad impressions on the client and on the server, without a shared id. Match each client impression to at most one server impression for the same user and ad within 5 seconds, closest first, and report the unmatched rate on each side.
Ads measurement at Meta depends on reconciling client and server views of the same impression, and onsite data engineering rounds probe this kind of fuzzy join. The interviewer checks a windowed non-equi join, enforcing one-to-one matching, and computing loss on both sides.
What the Interviewer Expects
- Joins on user and ad with a plus or minus 5 second time window
- Ranks candidate matches by absolute time difference
- Enforces one-to-one by ranking from both sides (mutual best match)
- Computes unmatched counts on both sides using anti joins
- Explains why a plain join double counts bursts of impressions
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
- Mutual best match can leave matchable pairs unmatched. How would you get a maximum matching?
- How would you choose the 5 second tolerance?
- How would you run this daily at scale?
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
client_imps(c_id, user_id, ad_id, ts) and server_imps(s_id, user_id, ad_id, ts), ids unique per side. Clock skew is small. A user can see the same ad twice in a few seconds (scrolling back), so a ...
Approach
- Candidate pairs: join on user and ad where
|c.ts - s.ts| <= 5s. - Rank each client row's candidates by distance, and each server row's candidates by distance.
- Keep pairs that are rank 1 on bo...