Skip to content
RED SAGSkills
mediumData Engineer interview question

Your source system sometimes sends the same event twice. How do you handle duplicates in your pipeline?

What the interviewer wants to hear

  • Identify a unique event ID or a natural key
  • Deduplicate with ROW_NUMBER or DISTINCT on the key
  • Use MERGE or upserts so loads are idempotent
  • In streaming, use stateful dedup with a time bound
  • Monitor duplicate rates

Model answer

First I find a reliable key, ideally an event ID created by the producer. If there is none, I build one from fields that together identify the event, like user_id, event_type and timestamp, and I push the source team to add a proper ID. In batch, I keep raw data as received, then in staging I deduplicate using ROW_NUMBER over the key ordered by ingestion time and keep row 1. When loading into the final table I use MERGE on the key, so reruns and retries do not add the same row again. In streaming, engines like Spark Structured Streaming or Flink support dropDuplicates with a watermark, so state is kept only for a limited time window. I also track the duplicate rate as a metric, because a sudden jump often means a bug upstream.

Can you answer it under time pressure?

Take a timed medium round and get scored on every answer.

Start mock interview

More medium Data Engineer questions