QUICK ANSWERData skew means a few keys hold far more rows than the rest, so after a join or groupBy one task gets most of the data and runs much longer (or fails with out of memory) while others finish in seconds. Detect it in the Spark UI by comparing max and median task times. Fix it with Adaptive Query Execution skew join handling, a broadcast join when one side is small, salting the hot key, or processing hot keys separately.
Learn this hands-on: covered in Week 4: Apache Spark of our 12-week Data Engineering course, with live labs and a trainer to help. See the full syllabus →

How to spot skew
- Spark UI → Stages → the slow stage → Summary Metrics.
- Compare Max with Median for duration and shuffle read size; a max 10x or more above the median is skew.
- Find the hot keys:
df.groupBy("customer_id").count().orderBy(F.desc("count")).show(10). - Common culprits: null or empty keys, a "default" or "unknown" value, one very large customer or store.
Fixes, from easiest
| Fix | When | How |
|---|---|---|
| AQE skew join | Spark 3+ sort-merge joins | spark.sql.adaptive.enabled and spark.sql.adaptive.skewJoin.enabled = true (defaults in recent versions) |
| Filter or handle nulls | Skew comes from null keys | Filter them out or process them separately |
| Broadcast join | One side fits in memory (tens to a few hundred MB) | df.join(F.broadcast(small), "key") |
| Salting | Huge hot keys on both sides | Add a random 0..N suffix to the hot key, replicate the other side N times |
| Two-stage aggregation | Skewed groupBy | Aggregate by (key, salt), then by key |
Salting example
from pyspark.sql import functions as F
N = 16
big = big.withColumn("salt", (F.rand() * N).cast("int"))
small = small.crossJoin(spark.range(N).withColumnRenamed("id", "salt"))
out = big.join(small, ["customer_id", "salt"]).drop("salt") Each hot key is now spread across 16 tasks instead of one. Salt only when AQE and broadcast joins are not enough, because it multiplies the smaller side.
Prevent it
- Check key distributions when you design a pipeline, not after it fails.
- Avoid partitioning output by a column with a few huge values; use date plus a better key, or liquid clustering on Delta tables.
- Keep AQE on and use recent Spark/Databricks runtimes.
Questions
Is skew the same as too few partitions?
No. With too few partitions every task is big. With skew, most tasks are small and a few are huge.
Does Databricks fix skew automatically?
AQE handles many skewed joins automatically, but extreme skew, skewed aggregations and null keys can still need manual fixes.