Home › Learn › Shuffle in motion

Shuffle in motion: watch one hot key stall a whole join

To join two tables, Spark sends every row with the same key to the same executor. That is the shuffle. When one key owns most of the rows, one executor gets buried while the rest sit idle. Drag the skew slider, then try the four ways to fix it and compare the job times.

0.0sJob time
1.0×Slowest task vs typical
0%Executor time wasted idle
0Rows sent over the network
Skew Join strategy

Skew is the share of rows that carry the one hot key, such as a single huge customer or a null key. Changing anything restarts the run.

What happened

Running...

Same data, four strategies

StrategyJob timeSlowest vs typicalNetwork rows

The four strategies, and when to pick each

StrategyHow it worksIn SparkVerdict
Plain shuffle joinHash the key, send each key to one executor.Sort-merge join, the default for two big tables.Fine when keys are even. Breaks on one hot key, and you only find out when the stage will not finish.
SaltingAdd a random suffix to the hot key so its rows spread over many executors. The small side is copied once per suffix.Hand-written: add a salt column to both sides, join on key plus salt.Works anywhere, including old Spark. Costs extra code and extra copies of the small side. Pursue only if adaptive split is not available.
Broadcast joinCopy the small table to every executor. The big table never moves.broadcast(df) hint, or automatic below spark.sql.autoBroadcastJoinThreshold (10 MB by default).The best fix when the small side really is small. Skew disappears because there is no shuffle. Drop it if the small side will not fit in memory.
Adaptive splitAfter the shuffle, Spark sees one partition is far bigger than the median and splits it into smaller tasks that other executors can take.Adaptive query execution with spark.sql.adaptive.skewJoin.enabled (on by default in current Spark).Pursue first. No code change. The rows still make the trip to the hot executor first, so it is not free.

Simplified on purpose: 240 rows, 4 executors, equal work per row, and the second table has one row per key. Real jobs have millions of rows, but the shape of the problem is exactly this.

Keep going

See where this fits in how Spark and Delta work, watch the whole pipeline in data in motion, or see what a commit writes in Delta in motion.