Data deduplication is a data-cleaning operation that detects redundant records and produces a dataset with the intended level of uniqueness. The first step is to define the dataset's grain: what one row represents. An order-line dataset might require uniqueness on order ID and line number, whereas an event dataset might use an event ID. Repeated customer IDs are not necessarily duplicates because one customer can legitimately place many orders.
Exact-row deduplication compares all relevant fields and removes identical rows. Key-based deduplication groups records by a business key and selects or constructs a surviving record. For example, when merging customer extracts from a CRM and a billing system, records may share a customer ID but contain different addresses. A retention rule might prefer the authoritative source or the most recent valid update. Approximate matching can identify likely duplicates with inconsistent names or addresses, but similarity alone does not prove that two records represent the same entity.
Standardization often precedes matching. Engineers can trim whitespace, normalize permitted case differences, standardize timestamps, and align data types across sources. These transformations must respect business meaning: lowercasing a case-sensitive identifier or removing meaningful punctuation can incorrectly merge distinct records. Missing keys also require explicit handling because grouping all missing identifiers together could discard unrelated records.
In SQL, SELECT DISTINCT eliminates duplicate combinations of the selected columns; it does not automatically choose the newest record for each business key. A common key-based pattern calculates ROW_NUMBER() OVER (PARTITION BY order_id ORDER BY updated_at DESC, ingestion_sequence DESC) in a subquery and retains row number one. The ordering must include a reliable tie-breaker when timestamps can be equal. UNION removes duplicate result rows, while UNION ALL preserves them and usually avoids the duplicate-elimination work. Neither operation resolves conflicting versions of a business entity without additional rules.
Cloud pipelines apply these techniques through SQL query engines, distributed processing frameworks, or custom code. Apache Spark provides distinct() and dropDuplicates(), but dropDuplicates() on a subset of columns does not guarantee retention of the newest row; use an explicitly ordered window when survivor selection matters. A notebook using pandas can explore duplicates and validate rules on a sample, while a distributed job applies those rules at production scale. Joining sources also requires care: a many-to-many join can multiply rows, and removing those rows afterward may conceal an incorrect join rather than fix it.
Deduplication has operational costs. Global grouping and sorting can require large distributed shuffles, memory, and temporary storage. Deduplicating individual files or partitions does not catch copies elsewhere unless the partitioning guarantees that matching keys are colocated. Streaming deduplication needs remembered identifiers or another persistent mechanism. Expiring that state limits cost but allows duplicates arriving after the retention period to pass through. Idempotent writes and conditional inserts help prevent retry-induced duplicates, but they do not repair duplicates already present.
For machine learning, repeated observations can overweight particular examples and distort class or subgroup distributions. Related copies appearing in both training and evaluation datasets can also inflate measured performance. Identify duplicate groups before splitting and assign each group to a single split when appropriate. Do not blindly remove legitimate repeated measurements or intentional sampling weights, and assess how removal changes label and subgroup distributions. Deduplication complements, rather than replaces, missing-value handling and outlier analysis.
Preserve immutable raw inputs, record the matching and retention rules, and validate the output with duplicate counts, key-uniqueness checks, and input-to-output reconciliation. Keep ambiguous matches available for review and retain lineage to the original records. Finally, distinguish record-level cleaning from storage-level deduplication: a storage system can share physical blocks without removing duplicate logical rows from queries, and storing files in object storage does not automatically deduplicate their records.