Data skew
| Also known as | Skew, hot keys, partition skew |
|---|---|
| Field | Distributed data processing |
| Key parts | Uneven partition sizes, straggler tasks, hot keys |
| Open source implementations | Apache Spark (AQE skew join), Apache Flink (adaptive skewed join, local-global aggregation), Trino |
| Related | Shuffle, Salting, Adaptive Query Execution, Spill (memory) |
Data skew is an uneven distribution of data across the partitions of a distributed computation, so that a few tasks process far more data than the rest and the whole stage waits for them. In Apache Spark, skew usually appears after a shuffle, when many rows share the same join or grouping key and all land in one task. Spark's Adaptive Query Execution (AQE) splits skewed join partitions automatically; other cases need manual fixes such as salting.[1]
How to recognize data skew in the Spark UI
Data skew shows up as a gap between the typical task and the slowest task in one stage. The Spark UI stage page shows summary metrics for all tasks of a stage, including task duration, GC time, shuffle read size and records, and shuffle spill.[2] A skewed stage has a maximum duration and shuffle read size many times the median. The REST API returns the same summary as quantiles, by default 0.0, 0.25, 0.5, 0.75 and 1.0, and accepts other quantiles such as ?quantiles=0.01,0.5,0.99.[3]
Other signs of skew in the Spark UI are spill or high GC time in only the largest tasks, which the per-task table on the same page shows, and a stage that sits at a few running tasks long after most have finished.[2] See Spill (memory) and Garbage collection in Spark.
What causes data skew?
- Hot keys. A join or
GROUP BYkey with one very common value (a default customer ID, a popular product,NULL) sends all of its rows to one shuffle partition, because a shuffle brings all the values for a key together in one place (hashpartitioningin the plan).[4] - Skewed source files. Uneven input files or table partitions give some scan tasks much more data than others. See Small files problem.
- Partitioning that does not match the data. Repartitioning by a low-cardinality column puts many rows in few partitions.
How Spark handles skew: AQE skew join
Spark 3.0.0 added a skew join rule to the new AQE framework.[5] After the shuffle stages on both sides of a join have run, AQE checks partition sizes. A partition is skewed when it is larger than spark.sql.adaptive.skewJoin.skewedPartitionFactor (default 5.0) times the median partition size and also larger than spark.sql.adaptive.skewJoin.skewedPartitionThresholdInBytes (default 256 MB). AQE splits such a partition into several tasks, replicating the matching partition of the other side.[1] The feature is on by default (spark.sql.adaptive.skewJoin.enabled) whenever AQE is on, and AQE is on by default since Spark 3.2.0.[1]
AQE can split only the sides that the join type allows. In Spark 4.3.0 it can split the left side of inner, cross, left semi, left anti and left outer joins, and the right side of inner, cross and right outer joins; it applies to sort-merge and shuffled hash joins.[6] Full outer joins and skewed aggregations are not split by this rule; for those, salting or a two-stage aggregation is still used.
For writes, the REBALANCE hint asks AQE to even out output partitions and to split skewed ones, which keeps very large files out of a Delta Lake or Apache Iceberg table.[7][1]
spark.sql.adaptive.enabled true
spark.sql.adaptive.skewJoin.enabled true
spark.sql.adaptive.skewJoin.skewedPartitionFactor 5.0
spark.sql.adaptive.skewJoin.skewedPartitionThresholdInBytes 256MB
Manual remedies
- Broadcast the small side. A broadcast join has no shuffle on the large side, so a hot key in the large table cannot pile up in one task. Use the
BROADCASThint when the small side fits.[1] - Salting. Add a random suffix to the hot key on one side and replicate the other side, so one key's rows spread over many tasks. See Salting.
- Filter or handle hot values separately. Rows with a
NULLjoin key never match in an inner join, so filtering them out before the join removes a common hot key. - Pre-aggregate. Aggregating before a join reduces the rows per key that the shuffle has to move.
Data skew compared across engines
| Apache Spark | Apache Flink | Trino | |
|---|---|---|---|
| Automatic skewed join handling | AQE skew join splits skewed sort-merge and shuffled hash join partitions at runtime; on by default[1] | The Adaptive Batch Scheduler's skewed join optimization splits skewed partitions in batch jobs; on by default, controlled by table.optimizer.skewed-join-optimization.strategy[8]
|
No dedicated skew splitting is documented; the cost-based optimizer can choose a broadcast join instead of a partitioned join[9] |
| Skewed aggregations | Partial aggregation before the shuffle (partial_sum in plans); salting by hand
|
Local-global (two-phase) aggregation, and split distinct aggregation (table.optimizer.distinct-agg.split.enabled)[10]
|
Not documented as a separate feature |
| Skewed writes | REBALANCE hint with AQE splits skewed output partitions[7]
|
Automatic balancing of data distribution in the Adaptive Batch Scheduler[8] | redistribute-writes (default true) hashes data across nodes before writing, to limit the effect of skew[11]
|
See also
References
- ↑ 1.0 1.1 1.2 1.3 1.4 1.5 Performance Tuning (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 2.0 2.1 Web UI (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Monitoring and Instrumentation (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ RDD Programming Guide: Shuffle operations (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ SPARK-29544: Optimize skewed join at runtime with new Adaptive Execution. Apache Software Foundation JIRA.Retrieved 2026-11-23.
- ↑ OptimizeSkewedJoin.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 7.0 7.1 Hints (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 8.0 8.1 Adaptive Batch Execution (Apache Flink 2.3). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Cost-based optimizations (Trino 484). Trino Software Foundation.Retrieved 2026-11-23.
- ↑ Performance Tuning (Apache Flink 2.3 Table API and SQL). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ General properties (Trino 484). Trino Software Foundation.Retrieved 2026-11-23.