Skip to content
Gold 6 min read · bucketBy 2 practice problems ↓

Bucketing

Pre-shuffle tables into buckets so joins and aggregations on the key skip the shuffle.

Step 2 · Spark internals · Gold · Layout tricks, lesson 2 of 2

Read first: Narrow vs wide transformations · Broadcast joins · Partitioning done right (skip if you know them)

In plain words first

A shop that always delivers by postcode can sort its parcels into postcode crates the moment they arrive, instead of sorting the whole warehouse every morning.

Bucketing is that early sorting: rows are hashed by the key into a fixed number of files at write time, so a join on that key finds matching rows already together.

Unlock the full lesson

You have read the free part. The rest of this advanced lesson:

  • What it does
  • What changes in the plan
  • Conditions
  • Costs and trade-offs
  • Try it yourself
  • Common mistakes
  • Key takeaways
  • Interview prep with 3 follow-up questions
  • Check yourself: 3 questions

Unlock it with the Complete pass (every advanced problem and lesson) or on its own.

Practise this

Problems that use this, graded on hidden tests

Keep going

Up next · new module: Spark 4 · 5 min read
Spark Connect
A thin client that talks to a remote Spark server over gRPC, and what it changes for applications.

Related lessons

Previous: Dynamic partition pruning

Primary sources: Bucketing (DataFrameWriter.bucketBy) · Performance tuning