On this page
01 Measure before touching anything 02 Send the small side to the data 03 Stop sorting what is already sorted 04 The result
A walk through the three changes that took a nightly aggregation from four hours to thirty-six minutes.
The job ran every night, took four hours, and nobody could say why. It had grown one feature at a time, and each feature had made sense on the day it was added. Together they made a pipeline that spent most of its life waiting.
Measure before touching anything
A profile of one full run showed that 61 percent of the time went into a single step: reading the same small dimension table once per partition, about forty thousand times. The expensive part was not the computation. It was the repetition.
Send the small side to the data
Instead of every worker fetching the dimension table over the network, we shipped one copy to each worker at the start of the run. The table was a few megabytes, so memory was never the constraint. Runtime dropped from 240 minutes to 118.
Stop sorting what is already sorted
Two stages in the middle of the plan sorted their input, and the input was already ordered by the upstream writer. Declaring the ordering removed both sorts and a full shuffle with them.
events .withOrdering("event_time") // already sorted upstream .join(dimensions.broadcast(), "account_id")
The result
Before: 4 hours, 0 minutes
After the broadcast: 1 hour, 58 minutes
After removing the sorts: 36 minutes, an 85 percent reduction
The fastest step is the one you can prove you do not need.
We kept the profile in the repository next to the job, so the next person who adds a feature can see what it costs before it ships.


