Idempotent taxi loads with a hashed key and MERGE
Module 2 of the Data Engineering Zoomcamp loads 1 month of yellow or green taxi trips per run into PostgreSQL, orchestrated by Kestra. Each run truncates a staging table, copies the month's CSV into it, adds a unique_row_id that is an md5 hash of 7 trip columns, and merges into the main table with MERGE ... WHEN NOT MATCHED THEN INSERT, so only rows the table has not seen go in. A scheduled version runs on the 1st of each month with a concurrency limit of 1 and can backfill the course's 2019 and 2020 files.
TLC trip records carry no trip id, so the flow builds one from the columns that describe a trip, and the merge on that hash turns a rerun of any month into a no-op. State the trade-off out loud: 2 different trips with identical values in all 7 columns collapse into 1 row. The concurrency limit matters as much, because 2 runs at once would truncate each other's staging table in the middle of a load.
To make it yours, run a month twice and diff the row count and a checksum of total_amount, then count how many rows the hash collapses. Replace the merge with a delete and reinsert of the month in 1 transaction and compare the 2 designs on the case that separates them: a corrected file for a month you already loaded.
"What happens if it runs twice?" is the first question a reviewer asks about any load. You can name the key, the statement that makes the rerun safe, the rows the hash cannot tell apart and the reason the flow refuses to run twice at once.





