Collapse Double-Fired Like Events Within Two Seconds
Last updated: November 29, 2026
Quick Overview
Client retries cause the same Facebook like to be logged several times. Collapse like events on the same post by the same user that occur within two seconds of the previous event into a single like, then count true likes per post per day.
Meta
November 29, 20260
0
0 solved
Client retries cause the same Facebook like to be logged several times. Collapse like events on the same post by the same user that occur within two seconds of the previous event into a single like, then count true likes per post per day.
Meta logging pipelines see duplicate client events from retries and flaky networks, and onsite data questions often test cleaning before counting. The interviewer wants gap-based dedup with LAG and a clear definition of when a repeat is a new like.
What the Interviewer Expects
- Partitions by user and post and orders by event time
- Uses LAG to compute the gap to the previous event
- Starts a new like only when the gap exceeds two seconds or there is no previous event
- Discusses chain behavior (events at 0s, 1.5s, 3s)
- Aggregates only the kept events per post per day
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
- Should the window be measured from the previous event or from the first event of the burst? What changes?
- How would unlike events change the logic?
- How would you dedupe if the client sends a stable event_id?
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
like_events(user_id, post_id, event_ts). No stable event id is available. Rule from the prompt: an event within two seconds of the previous event for the same user and post is a duplicate. I will co...
Approach
Within each (user, post), order by time, compute the gap to the previous event with LAG, and flag the event as a new like when the gap is NULL or greater than 2 seconds. Then count flagged events grou...