KatInterview

Design an Idempotent Incremental Data Pipeline for Big Data Tables

SQL & DataModel answer
MediumModel answerSQL & Datadata-engineeringsqletl

Last updated

Explain how to build a robust, idempotent daily incremental ingestion workflow that handles duplicates, backfills, and schema validation on large relational tables.

You are given a sample raw daily delta log (daily_order_events) from an upstream transaction database:

+------------+----------+-------------+--------+
| event_date | order_id | customer_id | amount |
+------------+----------+-------------+--------+
| 2024-05-20 | 1001     | 501         | 58.90  |
| 2024-05-20 | 1002     | 743         | 12.50  |
| 2024-05-21 | 1003     | 501         | 35.00  |
| 2024-05-22 | 1004     | 888         | 77.10  |
| 2024-05-22 | 1002     | 743         | 12.50  |
+------------+----------+-------------+--------+

Scenario

You need to maintain a large production analytical table (fact_orders) that captures order records without duplicates or inflated metrics. The upstream source drops daily files containing both new orders and repeated re-transmissions of historical records (as seen with order_id = 1002 on both 2024-05-20 and 2024-05-22).

Question

Describe your approach for designing a production-ready, daily incremental load process for this dataset:

  1. Architecture & Pipeline Logic: What structural steps ensure that re-executing a daily job for any arbitrary date range yields identical results (idempotency)?
  2. Duplicate Detection: How do you identify whether an arriving record is a brand-new insert, a state update, or an identical re-delivery? Provide the SQL and/or Python code to demonstrate this handling.
  3. Operational Robustness: How do you handle schema changes, out-of-order data, and failure recovery at scale?

Hints

Hint 1

Look carefully at order 1002: notice how event_date differs while the primary keys and payload remain unchanged.

Hint 2

Consider how window functions (ROW_NUMBER) combined with row-level hashing help distinguish between no-ops and actual payload updates.

Hint 3

Think about staging architecture: landing data in append-only partitions before applying MERGE statements.