SD-21 · Back to the write-up
Design a Sorting Large Data Sets
Sample keys to pick even ranges, sort blocks into runs per range, send each range to its owner, and merge each range into one part file.
Follow a request
Plan the job
Map: sort runs per range
Merge: one range into one part
A worker dies
A straggler near the end
Input
Plan
Sort and merge
Output
Job clientSubmits
Input files100 TB
CoordinatorTasks, retries
Key sampler249 split points
Task stateDurable
Map workersSort runs per range
Local disksSorted runs
Merge workersOne per range
Sorted outputParts + manifest
The numbers, at a glance
200 GB fits in memory400 GB share
≈ 135 min4× skew
≈ 39 minSampled
≈ 23 minCompressed
80% disk passes20% network shuffle
One range, in order
Shown for range 17; all 250 ranges run side by side.
Coordinator
Map worker
Local disk
Merge worker
Output
1 map task (256 MB block)
2 sorted runs per range
3 done, piece sizes
4 merge range 17
5 fetch piece 17
6 1.6 GB sorted piece
7 part-00017.attempt-1
8 done, count, checksum
9 rename, manifest last
RequestResponseAsync, does not block
How to split the work
The decision this question is really about.
250 sorted files
one merger
27+ hours
+ No shuffle.− A final merge of 100 TB on one machine.
hash(key) mod 250
each part sorted
parts overlap
+ Even shares.− Ranges overlap.
sample → 249 splits
map runs per rangeshuffle
250-way merge per range
+ Parts concatenate in order.− Needs a sample pass.
How it grows
Add a box only when a number forces you to. Highlighted boxes are new at each stage.
Input
Sort process
Output
Input
Sort processLocal disk runs
Output
CoordinatorKey sampler
Map workersLocal disk runs
Merge workers
Output
CoordinatorKey samplerTask state
Map workersCompressed runs
Merge workers
Output + manifest
Was this walkthrough useful?Your vote tells us what to improve next.