MapReduce

How MapReduce splits a big batch job into map, shuffle and reduce across many machines, how it survives failures, and why dataflow engines replaced it.

Overview

The idea

MapReduce is a way to process a dataset too big for one machine. Google described it in a 2004 paper by Jeffrey Dean and Sanjay Ghemawat, and Apache Hadoop made an open-source version widely used. The programmer writes two small functions. The framework runs them on thousands of machines and handles splitting the input, moving data, and recovering from failures.

  • Map runs once for each input record, on its own, and emits zero or more key-value pairs.
  • Shuffle is the framework's step: it collects every pair with the same key and brings them to one place, sorted by key.
  • Reduce runs once for each key, with all the values for that key, and writes the output.

The same shape in a few lines of Python, run on one machine, makes the three steps concrete.

Key concepts

  • Map
  • Shuffle
  • Reduce
  • Partitioner
  • Combiner
  • Data locality
  • Straggler
  • HDFS

Interview questions

  • Walk through a MapReduce job end to end. Where does each piece of data live?
  • How does MapReduce handle worker failures and slow machines?
  • How would you join two large datasets with MapReduce?
  • Why did Spark and other dataflow engines replace MapReduce?

Sign up free to read the full topic

More DDIA topics

Start free on Cariara · Coding problems · System design studio