Skip to main content
InterviewHubPRO
Section Overview
Q42

Question 42 of 50

Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

84%
Apache Spark Big Data (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

Data Skew Resolution Techniques: Salting partition keys and two-stage aggregations.

senior Levelapache-sparkAdvanced Internals

In Simple Words: When 90% of rows contain user_id = 'GUEST', all those rows route to a single partition, leaving 99 executors idle while 1 executor runs for 45 minutes:

  • Key Salting:
    1. Append a random integer (0 to 9) to the skewed key: concat(key, "_", floor(rand() * 10)).
    2. The skewed data evenly disperses across 10 separate parallel partitions.
    3. Perform the join or aggregation over salted keys.
    4. Strip the salt in a secondary aggregation to merge final totals.