PySpark Architecture
Scenario Q&A · Module 06c

Shuffle & Performance Tuning Q&A

Production-style questions with the answers a senior data engineer is expected to give: what the Spark UI shows, why it happens inside the engine, and the exact config or code that fixes it. Questions tagged from scenario notes are adapted from spark_devops_scenario_qna.md. Most link into the Shuffle Operations Lab so you can watch the problem happen.

Quick Reference: Shuffle Configs

The knobs every answer below keeps coming back to
ConfigDefaultWhat it controls
spark.sql.shuffle.partitions200Reduce-side partitions after a DataFrame exchange (AQE's starting point)
spark.sql.adaptive.enabledtrue (3.2+)Runtime re-planning: coalesce, skew join, join switch
spark.sql.adaptive.advisoryPartitionSizeInBytes64 MBTarget size when AQE coalesces / splits
spark.sql.adaptive.skewJoin.skewedPartitionFactor / ThresholdInBytes5 / 256 MBWhen a join partition counts as skewed (both must hold)
spark.sql.autoBroadcastJoinThreshold10 MBMax estimated size of a table to broadcast automatically (-1 disables)
spark.sql.files.maxPartitionBytes / openCostInBytes128 MB / 4 MBRead split size and per-file packing cost
spark.reducer.maxSizeInFlight48 MBShuffle bytes fetched concurrently per reducer
spark.memory.fraction0.6Heap share for execution + storage (unified memory)
spark.executor.memoryOverheadmax(384 MB, 10%)Off-heap: Netty, Python workers, Arrow — common OOMKilled cause
spark.sql.broadcastTimeout300 sHow long to wait for a broadcast to be built

Question Bank

Search, filter by topic and level, or switch on interview mode to hide answers until you've answered aloud

Interview Checklist

If you can explain these with numbers, you can handle most shuffle interviews
  • Spark skew: spot stragglers in the Spark UI; resolve with AQE skew join, salting or broadcasting — and know AQE only splits joins.
  • Partition sizing: target 100–200 MB per partition (128 MB default) — compute it from shuffle bytes.
  • Read the plan: count Exchange nodes; know which operations are narrow vs wide and why partial aggregation matters.
  • Sources: JDBC partitionColumn/bounds/fetchsize; splittable formats; small-file listing cost.
  • Targets: tasks × partition values = files; JDBC partitions = DB sessions; MERGE rewrites files.
  • Kubernetes debugging: kubectl logs --previous, exit code 137 = OOMKilled → memoryOverhead.
Back to the Shuffle Operations Lab