PySpark Architecture
Interactive Dashboard · Module 06b

Shuffle Operations Lab

Choose where the data comes from (object-store files, an RDBMS over JDBC, an MPP warehouse), what the DataFrame does (from a plain select to joins, windows and a full multi-shuffle pipeline), where it lands, and how big it is. The lab rebuilds the physical plan, stages, exchanges, partition sizes, spill, task timeline and tuning advice on every change.

The cost model is illustrative: it uses real Spark rules (maxPartitionBytes/openCostInBytes split sizing, hash/range partitioning, partial aggregation, AQE coalesce and skew-join thresholds, broadcast thresholds) with simplified throughput numbers. Use it to reason about shape and direction — then confirm on your cluster in the Spark UI.

1. Build a Workload

Source → DataFrame operation → Target, at a given volume, data shape and cluster config
50 GB
100MB1GB50GB1TB10TB
Workers × cores × executor RAM
Key shape (join / group / window key)
Skew = share of rows on the single hottest key (e.g. NULL or a default customer).
spark.sql.shuffle.partitions
spark.sql.autoBroadcastJoinThreshold
AQE (adaptive.enabled)
Salt the join key (×16)

2. Stages, Exchanges & Physical Plan

Every red arrow is a shuffle boundary: map tasks write shuffle files, reduce tasks fetch them over the network
Shuffle exchange (hash / range / round-robin) Broadcast exchange (no shuffle of the big side) Stage dependency Click a stage to inspect its tasks below
PySpark — generated for this scenario

          
out.explain("formatted") — simplified

          

3. Reducer Partitions & Executor Timeline

Where skew, empty partitions and spill come from — and what AQE does about them
Shuffle partition sizes
Executor task timeline
Task (≤ 3× median duration) Straggler (> 3× median) Rows = executor cores, grouped by worker · x = seconds

4. Tuning Advisor

Findings for the current workload, worst first, each with a fix

5. Same Workload, Varying Volume

100 MB → 10 TB under three configurations: why a fixed 200 partitions breaks at both ends
Simulated wall-clock timelog scale
Average shuffle partition sizelargest exchange · shaded = 64–256 MB sweet spot

6. Narrow vs Wide: When Does a Shuffle Happen?

Operation ladder from simple select to complex pipelines — click "Load" to simulate any row
Narrow — each output partition depends on one input partition
input partitionsoutput partitions

select · filter · withColumn · map · union · coalesce — pipelined in one stage, no data movement.

Wide — each output partition reads from every input partition
map tasks (shuffle write)reduce tasks (shuffle read)

groupBy · distinct · join (non-broadcast) · orderBy · window · repartition — stage boundary, disk + network.

7. Sources: How Read Partitions Are Born

The first stage's task count is decided by the source, not by shuffle.partitions

8. Targets: How the Last Stage Shapes Output

One task = one file (per partition directory) or one DB connection
Ready for the hard questions?
Scenario-based performance-tuning Q&A: skew, AQE limits, JDBC, small files, spill, cluster sizing, Delta MERGE and production triage.
Open Tuning Q&A