Skip to content

A scenario for a data engineer · Junior and up

One task has been running for an hour

Patch · Your teammate
Friday, 10:30

A Spark join on Databricks between two billion order rows and a table of 300 stores is stuck. Almost every task finished in seconds and one is still going. One store holds nearly half the orders, and Spark did not broadcast the store table by itself.

What do you do?

Tap the one you would do. The answer opens below.

Show the best call

Add a broadcast hint for the small store table, so the join needs no shuffle.

Every worker gets the whole store table, the orders are never shuffled by store, and the job finishes in minutes.

Why

A skewed key puts most rows in one shuffle partition, and one task has to work through all of it. A broadcast join sends the small table to every worker, so the big table is never shuffled by that key. Spark usually broadcasts a table this small by itself, and adaptive query execution can split skewed partitions. When neither happens, a broadcast hint fixes it.

Read it in the Databricks docs (opens in a new tab)

The other two

Works, at a price. Add a random salt to the store key on the orders, and copy each store once for every salt value.
It works, and the query is now harder to read and easier to get wrong.
A poor call. Double the number of workers.
The stuck task is one task. It runs on one worker however many you add.

The words in this scenario

Broadcast join.
A join where Spark sends a copy of the small table to every worker, so the large table does not have to be moved around to meet it. In the docs (opens in a new tab)

Go deeper on brickster.ai

More scenarios

Had one like this at work? Send it to us: the best tickets come from real incidents.

Checked against the Databricks documentation on . brickster.ai is independent and is not affiliated with Databricks.