SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 21
Design a system to sort a 100 TB dataset
A data team has 100 TB of records spread over thousands of files and needs them globally sorted by key, so downstream jobs can merge-join and binary-search them. You have a cluster for a few hours and need a plan that finishes on time even when some machines misbehave.
Requirements
- Produce output files that are each sorted, where every key in file i is less than or equal to every key in file i+1.
- Every input record appears in the output exactly once.
- Survive machine failures without restarting the whole job.
Constraints and assumptions
- 100 TB of 100-byte records with 10-byte keys, stored as 10,000 input files of 10 GB in object storage.
- 100 machines, each with 128 GB RAM, 4 NVMe drives (about 2 GB/s each), and a 25 Gbps network link.
- Object storage delivers about 1 GB/s of reads or writes per machine.
- Keys are skewed: some key prefixes are far more common than others.
- The job must finish within 2 hours.
Out of scope for the first sketch
Continuous or incremental sorting of new data · Sorting records by more than one key · Encryption and multi-tenant isolation
Draw your design
Rough math and notes
SYSTEM DESIGN SKETCHBOOK / FOLLOW-UPS
Design a system to sort a 100 TB dataset
Finish your first sketch before answering these. Cross out freely.
- How many times does each byte cross the network or touch a disk? Which resource sets the finish time?
- Half of all keys start with the same 3-byte prefix. How do you keep one machine from receiving most of the data?
- Ten machines are running at half speed. How do you stop them from setting the end time of the whole job?
- A machine dies after the shuffle is 80% done. What work is redone, and how do you avoid duplicate records in the output?
Compare afterwards: worked approaches and reading at sketchbook /questions/sort-large-dataset/review