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
On this page
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 readSpark Connect
A thin client that talks to a remote Spark server over gRPC, and what it changes for applications.
Related lessons
Broadcast joinsData lake & lakehouse · 5 min read
Liquid clusteringSpark internals · 6 min read
Narrow vs wide transformations
Previous: Dynamic partition pruning
Primary sources: Bucketing (DataFrameWriter.bucketBy) · Performance tuning