Deduplicate a Card Transaction Feed to Each Transaction's Latest Version

Last updated: November 29, 2026

Quick Overview

A transaction feed receives repeated records for the same transaction as it moves from pending to posted or is reversed. Return one row per transaction with its latest version, excluding transactions whose latest status is reversed.

Capital One
Data Manipulation (SQL/Python)
Data Engineer
Capital One
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


A transaction feed receives repeated records for the same transaction as it moves from pending to posted or is reversed. Return one row per transaction with its latest version, excluding transactions whose latest status is reversed.

Capital One's data platform ingests card events from processors where the same transaction id arrives several times, sometimes out of order and sometimes as exact duplicates. The interviewer checks ROW_NUMBER based deduplication, a deterministic tie-breaker, and filtering on the latest state rather than any state.

What the Interviewer Expects
  • Partitions by transaction id and orders by the source update time
  • Adds a tie-breaker such as ingestion sequence
  • Filters reversed transactions after choosing the latest version
  • Distinguishes exact duplicates from legitimate updates
  • Mentions QUALIFY or an equivalent in warehouses that support it
Key Topics to Cover
deduplication
ROW_NUMBER
late data
idempotency
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you do this incrementally with a MERGE into a target table?
  • What if a late-arriving older version shows up after the newer one was loaded?
  • How would you detect a processor sending the same event with two different transaction ids?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data
  • txn_feed(txn_id, account_id, amount, status, source_updated_at, ingest_seq) where status is pending, posted, or reversed.
  • The source timestamp decides recency. Records can arrive out of or...
Approach

Rank versions per txn_id by source_updated_at DESC, ingest_seq DESC, keep rank 1, then drop reversed. Order of operations matters: filtering out reversed rows first would surface the pending versi...


Submit Your Answer
Markdown supported