Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Deduplicate Late Meta Event Logs

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Deduplicate Late Meta Event Logs. Start with the requirements and the one table on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Meta’s event pipeline for Facebook activity can receive the same logical event multiple times, and some duplicates arrive late. Write a SQL query to return one canonical row per event_id, keeping the most recently ingested record.

Requirements

  1. Only consider events with a non-null event_id.
  2. Deduplicate by event_id across the full table, even if duplicates arrive on different ingestion dates.
  3. Keep the row with the greatest ingested_at for each event_id.
  4. If two rows for the same event_id have the same ingested_at, keep the one with the greater record_id.
  5. Return event_id, user_id, event_name, event_time, and ingested_at.
  6. Order the final result by event_id ascending.

Schema

meta_event_log
ColumnTypeDescription
record_idPKINTUnique identifier for each ingested row
event_idVARCHAR(50)Logical event identifier used to detect duplicates
user_idINTUser associated with the event
event_nameVARCHAR(50)Type of event generated on a Meta surface
event_timeTIMESTAMPTimestamp when the event occurred
ingested_atTIMESTAMPTimestamp when the event record arrived in the warehouse
source_surfaceVARCHAR(50)Meta product surface that emitted the event
Tablesmeta_event_log
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results