What strategies would you use to manage and mitigate data skew in a distributed data processing environment?
Instruction: Discuss how you address and rectify data skew to ensure balanced data processing.
Updated
Official answer
Data skew means some partitions or tasks carry much more work than others. Inspect task duration, input/shuffle bytes, spill and key frequencies; expensive records can create compute skew even with equal row counts. Hash partitioning does not split one hot key across multiple partitions by itself.
Choose a response for the operation. Preaggregate associative summaries where possible, broadcast a genuinely small join side when memory permits, isolate exceptional keys, or use supported adaptive skew-join handling. Rescheduling a hot partition onto another worker does not remove its intrinsic size.
Salting can split a hot key, but must preserve semantics. For a sum, aggregate by (key, salt), then sum those partial sums by key. For an average, merge partial sums and counts, not unweighted averages. For a join, replicate or compatibly partition the matching side across salts as required; independent random salts on both sides lose matches.
Use deterministic salt assignment when replay reproducibility matters, bound the replication cost, and remove the temporary salt before the final output. Validate the complete output multiset and totals against a small exact reference. More partitions may reduce imbalance or add overhead; benchmark the actual distribution, including null and unusually frequent keys.