Skip to content
SD-21 · System design

Design a Sorting Large Data Sets

Asked at Mid level45 minutes
Our answers stay hidden until you reveal them.

Design a service that sorts data sets far too large for one machine. A team points it at a folder of input files in object storage, names the key to sort by, and gets back a folder of sorted output files and a manifest. The output must contain exactly the input records, in key order, so that reading the part files one after another gives one sorted sequence.

A typical job is 100 TB: a trillion 100-byte records with 10-byte keys, and it should finish in under 30 minutes on a pool of 250 machines. The hard parts: no machine can hold more than a sliver of the data in memory, every byte has to cross the network once and touch disk several times, one overloaded machine sets the finish time for everyone, and in a 30-minute run on 250 machines, about one machine is likely to die.

Good questions to ask first

Decide what you would assume for each before you look at ours.

  1. 1How much data per job?
  2. 2What is a record?
  3. 3Does the output have to be one file?
  4. 4How fast?
  5. 5What machines?
  6. 6Can machines fail mid-job?
  7. 7Duplicate keys and stability?
  8. 8How many jobs at once?

How to spend the 45 minutes

  1. 5minPart 1: Requirements and scope
  2. 5minPart 2: Estimates: memory, disk and network passes
  3. 5minPart 3: API
  4. 15minPart 4: Architecture, stage by stage
  5. 15minPart 5: Deep dives and trade-offs
Sketch your own design: boxes, arrows and the numbers that matter. Then compare it with ours.Break it in the labVisual walkthrough