TICKIT-08: Silver Conform, Dedupe and MERGE
Track: TICKIT Marketplace • Difficulty: Intermediate • Mastery Points: 150 PTS
Business Problem Scenario
Due to upstream network retries and webhook replay attacks, raw transactions in bronze.sales_raw contain duplicate payloads for identical salesid records. In the Silver medallion layer, data must be conformed and deduplicated. You must author an atomic MERGE INTO silver.sales statement that deduplicates incoming records by selecting the latest event using ROW_NUMBER() and updates existing rows or inserts new ones.
Engineering Objective
Write an idempotent MERGE INTO silver.sales statement sourcing from deduplicated bronze sales. • Deduplication & Merge Logic: - Filter bronze with ROW_NUMBER() OVER (PARTITION BY salesid ORDER BY _ingest_ts DESC) = 1. - Match target silver.sales t on t.salesid = s.salesid. - WHEN MATCHED THEN UPDATE SET * - WHEN NOT MATCHED THEN INSERT * Key Concepts: - Idempotent Ingestion: Guaranteeing that reprocessing an ingestion batch produces identical, consistent target state.
Target Table: bronze.sales_raw s, silver.sales t (salesid INT, listid INT, sellerid INT, buyerid INT, eventid INT, dateid INT, qtysold INT, pricepaid DECIMAL(10,2), commission DECIMAL(10,2), saletime TIMESTAMP)
Verification & Architecture Insights
Idempotent silver merges guarantee deterministic pipeline reruns, preventing duplicate revenue records even after upstream network replays.