This was basically the whole interview compressed into one question.
Start by framing the problem as a batch ETL with idempotency and late-data handling, then walk through a layered solution: staging with deduplication, a MERGE with update guards, and a watermark plus DQ checks. Emphasize trade-offs between correctness and performance, and show how each component addresses a specific failure mode.
Pro tip: In Amazon interviews, explicitly connect your design to operational realities like rerun frequency, data volume, and SLA impact—this shows you think beyond code and understand production data pipelines.
Ask about data volume, update frequency, acceptable latency, and whether the fact table is append-only or mutable. Confirm the definition of 'last 7 days' and how late data is expected.
Load raw data into a staging table, then use a dedupe CTE with ROW_NUMBER() partitioned by order_id ordered by update_timestamp DESC to keep the latest record per order.
Write a MERGE that inserts new orders and updates existing ones only when the incoming update_timestamp is greater than the target's, ensuring reruns don't regress data.
Maintain a watermark table storing the max update_timestamp processed; on each run, reprocess a lookback window (e.g., 3 days) to catch late updates. Use row hashing to detect unchanged rows and skip unnecessary updates.
Implement checks like row count within expected range and no duplicate order_ids in the target; if any fail, rollback the transaction and alert.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.