Diagnosing and fixing data skew in Spark
distributed processing skew.
this is data skew, caused by uneven key distribution concentrating rows on few partitions; mitigate with salting, broadcast joins, repartitioning, or adaptive execution.
just adding more executors.
What's really being asked
This checks whether you can identify the classic distributed-computing pathology of uneven load and apply the right targeted fixes rather than throwing hardware at it.
The full answer
The symptom of a few tasks running far longer than the rest is data skew. In a shuffle, such as a join or group-by, rows are partitioned by key, and if some keys hold a hugely disproportionate share of rows, the tasks handling those keys process far more data and become stragglers that dominate the stage's wall-clock time while other tasks finish and sit idle. Common causes include hot keys like a default or null value, a dominant entity such as one giant customer, or naturally Zipfian distributions. Mitigations depend on the operation. For joins where one side is small, a broadcast join avoids the shuffle entirely. For skewed shuffle keys, salting adds a random suffix to the hot key to spread it across partitions, with the other side replicated accordingly. You can isolate and process skewed keys separately, then union the result. Repartitioning or increasing shuffle partitions helps mild cases. Modern Spark's Adaptive Query Execution can detect and split skewed partitions automatically. Filtering or pre-aggregating before the shuffle also reduces the volume on hot keys.
The mistakes people make
Simply adding more executors or memory, which does not rebalance a skewed key still pinned to one task. Increasing partitions blindly without addressing the dominant key. Confusing skew with a small-files or memory problem. Forgetting that nulls often collapse onto a single partition.
What usually comes next
How exactly does salting work. When is a broadcast join unsafe. How does AQE detect skew.
A concrete example
A join on customer_id stalls because one wholesale account owns most rows. Salting that key into several variants spreads its rows across many tasks, the straggler disappears, and the stage finishes in a fraction of the time.
Interview question
A Spark join stage finishes only after one task processing a single hot key completes. Which fix targets the root cause?
- a.Increase driver memory
- b.Salt the hot key to spread its rows across partitionsCorrect
- c.Cache the input DataFrame
- d.Add more executor nodes to the cluster
Why? this is the answer
Salting redistributes a dominant key's rows across many tasks, removing the straggler. Adding executors or memory does not rebalance rows that remain concentrated on one partition key.
Just read this? Test yourself on what you have been reading.
Read the original → spark.apache.org
- #spark
- #data-skew
- #distributed-systems
- #performance
- #data-engineering
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles