Output is 12 000 tiny files
Symptoms
- Every file is a few MB
- Next job launches 12k tasks
Interactive Spark interview questions on Partitions: the unit of parallelism. Same topic as /learn/spark/partitions. One partition is one chunk of data. One task processes one partition in a stage. Size them for 128–256 MB.
Question 1 of 3
What is a Spark partition?
Answer it out loud, then reveal. Play steps through like the simulators.
Case 1 of 1 · symptoms
Symptoms
Indexed as FAQ. Open any item if you prefer a list to Play.
What is a Spark partition?
Partitions: the unit of parallelism · tap to open the answer
Short: A chunk of a DataFrame that one task reads in a stage.
Detailed: Input partitions often follow files. After a shuffle, spark.sql.shuffle.partitions (or AQE) decides how many. One partition = one task, not one executor.
Common mistake: One partition per executor as a rule.
Follow-up: Who decides input partitions for a Parquet scan?
repartition vs coalesce — when do you use each?
Partitions: the unit of parallelism · tap to open the answer
Short: repartition shuffles to a new count. coalesce reduces without a full shuffle (can stay unbalanced).
Detailed: repartition(n) for even parallelism or a join key. coalesce(n) after a filter that dropped most rows, to avoid a shuffle. Don't coalesce to 1 on a huge frame except for a tiny output.
Common mistake: coalesce(1) to 'make a single CSV' on a 400 GB table.
Follow-up: What does partitionBy on write control versus RDD partitions?
How do you size partitions for a shuffle?
Partitions: the unit of parallelism · tap to open the answer
Short: Aim for ~100–256 MB per shuffle partition, then look at the histogram.
Detailed: Too few: fat tasks, spill, OOM. Too many: scheduler overhead. AQE coalesce helps small data. Skew means one partition will still be fat — salting, not more partitions, fixes that.
Senior: You want enough partitions for cores × duration, sized by data bytes, not by machine count.
Common mistake: Setting shuffle partitions to executor_count.
Follow-up: Why is executor_count the wrong formula?