How do I build a reliable data pipeline that doesn't create duplicates on retry?

poze 2 months ago348 gadeen

0

My nightly job loads yesterday's transactions from an API into our warehouse. When it fails halfway and I rerun it, I get duplicate rows.

Dyagnostik IA

Se IA ki fè l. Se pa yon repons — kominote a anba a konfime oswa korije l. Toujou verifye anvan ou fye l.

1 Repons

3
✓
✓ Repons yo aksepte

Make every load idempotent: running it twice must produce the same result as running it once.

1. Upsert (MERGE) on a natural key instead of blind INSERT:

MERGE INTO fact_transactions t
USING staging_transactions s
  ON t.transaction_id = s.transaction_id
WHEN MATCHED THEN UPDATE SET amount = s.amount, status = s.status
WHEN NOT MATCHED THEN INSERT (transaction_id, amount, status, tx_date)
  VALUES (s.transaction_id, s.amount, s.status, s.tx_date);

2. Or delete-then-insert per partition, in one transaction: DELETE WHERE tx_date = '2026-09-25', then insert that day's data. 3. Load to staging first, validate (row counts, nulls, sums), then merge in a single transaction. A half-finished run never touches the final table. 4. Parameterize by date (--date 2026-09-25) instead of "yesterday", so backfills and reruns are explicit. 5. Record each run in a load_log table (date, rows, status) for monitoring.

Konekte pou di lòt moun si li te mache.

answered 2 months ago

Sign in and verify your email to post an answer.