Why AQE coalesces shuffle partitions
Adaptive Query Execution merges tiny post-shuffle partitions at runtime, so stop hand-tuning spark.sql.shuffle.partitions for every job.
The takeaway
With AQE on (default since Spark 3.2), Spark looks at the actual size of shuffle output at runtime and merges small partitions to hit a target size (~64 MB). The old ritual of tuning spark.sql.shuffle.partitions per job is mostly obsolete — set it generously and let AQE coalesce down.
Context
A job aggregated a filtered slice of events — maybe 400 MB after the WHERE. With shuffle.partitions=200, that meant 200 partitions of ~2 MB: 200 tasks, each finishing in milliseconds, scheduler overhead dominating.
Example
spark.conf.get("spark.sql.adaptive.enabled") # true
spark.conf.get("spark.sql.adaptive.coalescePartitions.enabled") # true
df = (spark.table("bronze.events")
.where("event_date = current_date()")
.groupBy("user_id").count())
df.write.mode("overwrite").saveAsTable("tmp.daily_counts")In the Spark UI the exchange shows AQEShuffleRead — 200 configured partitions read back as 7 coalesced ones. Stage time dropped from 48 s to 11 s on the same cluster.
Why it matters
Fewer, right-sized partitions mean less task overhead and fewer small output files (small-file problem solved at the source). Interview angle: "how do you choose shuffle partitions?" — the modern answer starts with AQE, not with a magic number.
Go deeper
- Related article: Window functions you will actually use in pipelines
Keep going
Window functions you will actually use in pipelines
Four window patterns cover almost every pipeline need: latest-row dedupe, sessionization, running totals and gap detection — with the performance traps of each.
Cost control for Databricks job clusters
The five levers that actually move a Databricks bill: job clusters over all-purpose, right-sized autoscaling, spot instances, photon where it pays, and killing idle time.
Why AQE Coalesces Shuffle Partitions (and When It Can't Help)
How Adaptive Query Execution merges small shuffle partitions at runtime, the settings that control it, and the cases where you still have to tune.
One practical note a week
Get new articles, problems and guides in your inbox.
Thanks! You're on the list. (Local demo — no email provider is wired up yet.)