Map tasks sort and write blocks to local disk, reducers fetch them over the network — the costliest step in most jobs.
groupBy("customer_id") can only produce a correct total if all of a customer's rows end up in the same task. But input partitions follow the file layout, not the keys — any customer can appear in any of them. So every map task must send each row to the partition that owns its key: an all-to-all exchange called the shuffle.
Spark SQL picks the target with a hash: partition = hash(key) mod N, where N is the number of shuffle partitions. Joins, distinct, window functions with partitionBy, repartition and orderBy (range-partitioned instead of hashed) all shuffle for the same reason.
from pyspark.sql import functions as F
orders = spark.read.parquet("s3://lake/orders/")
totals = orders.groupBy("customer_id").agg(F.sum("amount").alias("total"))
totals.explain()
# ... Exchange hashpartitioning(customer_id, 200) ...Reach the last step for the run summary: the key takeaways from this lesson.