1. Reduce the shuffle payload
Select only the join key and attributes you need from each side. Filter by the target partition or change window when the output contract allows it. Check lookup key uniqueness before joining to avoid multiplying rows.
2. Inspect the physical plan
lookup = attributes.select("consumer_id", "segment_code")
joined = changed_ids.join(lookup, "consumer_id", "left")
joined.explain("formatted")
Inspect the Spark UI after running a representative job. Compare shuffle read and write, spill, and the duration of the slowest tasks. Large gaps between median and maximum task duration can signal skew. Check the frequencies of hot keys, including blank or default values.
3. Compare one change at a time
Measure total run cost and elapsed time on the same input. Keep adaptive execution enabled where supported and check its final plan. Consider broadcast only if the projected lookup safely fits in executor memory. Before publishing, compare output counts, key cardinality, and unmatched rows against your baseline.