PAPER EXPLAINED
MapReduce: Simplified Data Processing on Large Clusters
IntermediateAbout 40 min to read the paper
TL;DR
MapReduce lets programmers write just a map and a reduce function, while a library automatically parallelizes the job across thousands of commodity machines and handles failures, stragglers and data movement.
What problem does MapReduce solve?
Many of Google's data computations, such as building inverted indices or counting queries, were conceptually simple but had to run on hundreds or thousands of machines to finish in reasonable time. Each one needed large amounts of custom code to split up the work, distribute data, balance load and survive machine failures, which are common in large clusters of cheap hardware. That code buried the simple logic and had to be rewritten for every new task.
The core idea
Express a computation as two user functions. Map turns each input record into intermediate key/value pairs. Reduce receives all values that share a key and combines them. Because these functions are restricted in this way, a library can split the input into many small tasks, run them anywhere, and re-run any task that fails or runs slowly. The programmer sees what looks like a simple sequential program, while the library handles parallelism, fault tolerance, locality and load balancing.
IN THE AUTHORS’ WORDS
“When a MapReduce operation is close to completion, the master schedules backup executions of the remaining in-progress tasks.”
MapReduce: Simplified Data Processing on Large Clusters, p. 6
“Network bandwidth is a relatively scarce resource in our computing environment.”
MapReduce: Simplified Data Processing on Large Clusters, p. 5
“restricting the programming model makes it easy to parallelize and distribute computations and to make such computations fault-tolerant.”
MapReduce: Simplified Data Processing on Large Clusters, p. 12
How MapReduce works
- The library splits the input into M pieces, typically 16-64 MB each, and starts copies of the program on a cluster. One copy acts as the master, which assigns M map tasks and R reduce tasks to idle workers.
- A map worker reads its split, passes each key/value pair to the user's Map function, and buffers the output. It periodically writes that output to local disk, divided into R regions by a partitioning function such as hash(key) mod R, and reports the locations to the master.
- Reduce workers fetch their region from map workers' disks over remote procedure calls and sort it by key, using an external sort if needed. They then call the user's Reduce function once per unique key and append the results to that partition's output file.
- The master pings workers periodically. Tasks on a worker that stops responding are reset to idle and rescheduled, including its completed map tasks, because their output sat on the lost disk. Atomic commits and renames ensure only one execution of each task counts.
- To save scarce network bandwidth, the master tries to schedule map tasks on or near machines that already hold a GFS replica of the input data.
- Near the end of a job, the master launches backup copies of the remaining in-progress tasks and uses whichever copy finishes first. This limits the damage from stragglers.
- Optional refinements include custom partitioning functions, sorted order within each partition, combiners that pre-merge data on map machines, skipping records that crash user code, a local sequential mode for debugging, and counters.
Results
On a cluster of about 1800 machines, a grep over about 1 TB took roughly 150 seconds, including about a minute of startup overhead, and peaked above 30 GB/s. Sorting about 1 TB took 891 seconds, which the authors call similar to the best reported TeraSort result of 1057 seconds. Without backup tasks the sort took 1283 seconds (44% longer). Killing 200 of 1746 workers raised the time only to 933 seconds (5% longer). Caveats: the runs used a mostly idle cluster, and the sort's partitioner had built-in knowledge of the key distribution. Separately, Table 1 reports 29,423 jobs in August 2004, and one indexing phase shrank from about 3800 to about 700 lines of C++.
Limitations and what came later
- The single master is a single point of failure. The current implementation aborts the whole computation if the master dies, leaving clients to retry.
- The clean guarantee of matching a sequential run holds only for deterministic map and reduce functions. With non-deterministic functions, different reduce outputs may reflect different executions of the same map task.
- There is no atomic two-phase commit across multiple output files from one task. Side effects must be made atomic and idempotent by the application writer.
- M and R have practical upper bounds, because the master makes O(M+R) scheduling decisions and keeps O(M*R) state in memory.
- The performance runs were done when the cluster was mostly idle. The sort benchmark used a partitioner tuned to the known key distribution, which a general sort would need to replace with a sampling pre-pass.
Why MapReduce matters
The paper shows that a narrow programming interface can let programmers with no distributed-systems experience use thousands of machines. It also shows that re-execution, locality-aware scheduling and redundant backup tasks are enough to make such jobs robust on unreliable commodity hardware. The authors report broad internal adoption, including a rewrite of Google's production indexing system. They also distill general lessons: restrict the programming model, treat network bandwidth as scarce, and use redundant execution to handle slow and failed machines.
This paper shows how a small, restrictive programming interface can hide most of the work of large-scale distributed computing. Users write only two functions, map and reduce. The library takes care of splitting the input, scheduling work, recovering from machine failures, and moving data between machines. The paper explains the design choices behind that, including re-execution for fault tolerance, locality-aware scheduling to save network bandwidth, and backup tasks for slow machines. It backs them with concrete measurements: a terabyte grep, a terabyte sort, a run with backup tasks turned off, and a run with deliberately killed workers. It also reports usage statistics from Google's own clusters. Its main lesson is that restricting what programmers can express makes parallelism and fault tolerance much easier to provide automatically, and that lesson applies well beyond this one system. The paper is short, concrete and readable, and works well as a case study in systems design under real hardware constraints.
Before you read
Who it’s for
Students and engineers interested in distributed systems, data processing or systems design. It also suits anyone who has used batch data-processing frameworks and wants to see the original design reasoning behind the map/reduce model.
What to know first
- Basic programming, including functions applied over collections
- Familiarity with key/value pairs and hashing
- A rough idea of what a cluster of networked machines is
- Basic understanding of disks, networks and why network bandwidth can be a bottleneck
- Helpful but optional: the idea of map and reduce in functional programming
Glossary
- Map function
- A user-written function that takes one input key/value pair and emits a set of intermediate key/value pairs.
- Reduce function
- A user-written function that receives one intermediate key and an iterator over all its values, and merges them into a usually smaller set of output values.
- Master
- The special copy of the program that tracks the state of every map and reduce task, assigns tasks to idle workers, and passes intermediate file locations from map tasks to reduce tasks.
- Partitioning function
- A function on the intermediate key that decides which of the R reduce tasks receives each pair. The default is hash(key) mod R.
- Straggler
- A machine that takes unusually long to finish one of the last tasks, for example because of a bad disk or competition from other jobs, which delays the whole computation.
- Backup task
- A duplicate execution of a still-running task, launched near the end of a job. Whichever copy finishes first marks the task as complete.
- Combiner function
- An optional function that partially merges intermediate data on the map machine before it is sent over the network. It is usable when the reduce function is commutative and associative.
- Locality optimization
- Scheduling map tasks on or near machines that store a replica of their input data, so most input is read from local disk instead of over the network.
- GFS
- The in-house distributed file system MapReduce reads from and writes to. It splits files into 64 MB blocks and typically stores 3 replicas of each block on different machines.
What to pay attention to
- The seven-step execution flow tied to Figure 1 (page 4), especially where intermediate data lives: on map workers' local disks, not the global file system.
- Why completed map tasks must be redone after a worker failure while completed reduce tasks do not (page 4).
- How atomic renames and the master ignoring duplicate completion messages give clean semantics for deterministic functions, and the weaker guarantee for non-deterministic ones (page 5).
- The locality optimization and the paper's repeated point that network bandwidth is scarce (pages 5, 12).
- Backup tasks for stragglers and the measured cost of disabling them in the sort experiment (pages 6, 10).
- The conditions under which a combiner is safe to use: repeated keys and a commutative, associative reduce (page 6).
- Experimental context: about 1800 machines, run on a mostly idle weekend afternoon, and a sort partitioner with built-in knowledge of the key distribution (pages 8-9).
Questions to keep in mind
- Why does restricting computations to map and reduce make automatic parallelization and fault tolerance easier than with a general parallel programming interface?
- What trade-off is made by storing intermediate data on local disks instead of the replicated global file system?
- Why does the design accept a single master whose failure aborts the whole job? When might that choice become a problem?
- How do backup tasks reduce completion time, and what extra resource cost do they introduce?
- Which kinds of computations would be awkward or inefficient to express as a single map and reduce pass, based on the examples and refinements in the paper?
MapReduce quiz: check your understanding
1. When a worker fails, why are its completed map tasks re-executed but its completed reduce tasks are not?
Show the answer
Map output is stored on the failed machine's local disk, so it becomes inaccessible. Reduce output is written to the global file system, so it survives the failure (page 4).
2. In the sort experiment, what happened when backup tasks were disabled?
Show the answer
After 960 seconds, all but 5 reduce tasks had finished. Those last stragglers took another 300 seconds, so the whole job took 1283 seconds. That is 44% longer than the normal run (page 10).
3. What is a combiner function, and when is it appropriate?
Show the answer
It is an optional function that runs on each map machine and partially merges intermediate data before it is sent over the network. It is useful when there is significant repetition in intermediate keys and the reduce function is commutative and associative, as in word counting (page 6).
4. What does the implementation do if the master fails?
Show the answer
The current implementation aborts the MapReduce computation. Clients can detect this and retry if they want. The authors note that checkpointing the master's state would be easy, but they consider master failure unlikely because there is only one master (page 5).
5. How is intermediate data divided among reduce tasks by default, and how can a user change this?
Show the answer
The default partitioning function uses hashing, for example hash(key) mod R. Users can supply their own, such as hash(Hostname(urlkey)) mod R, so that all URLs from the same host end up in the same output file (pages 4, 6).
6. How does MapReduce save network bandwidth when reading input?
Show the answer
The master uses the location of the input file replicas in GFS. It tries to schedule each map task on a machine holding a copy of its input, or failing that, on a machine nearby, such as one on the same network switch. In large runs, most input is then read locally (page 5).
7. What happened when 200 of 1746 worker processes were killed during the sort?
Show the answer
The cluster scheduler restarted the processes, and the lost map work was redone fairly quickly. The job finished in 933 seconds, about 5% longer than the normal execution (page 10).
Go a little deeper
The paper argues that a restricted programming model is what makes automatic parallelism and fault tolerance practical. Using the paper's own mechanisms (re-execution, atomic commits, backup tasks), work out which properties of user code they depend on, such as determinism and the absence of side effects. What breaks, and how much, when those properties are violated?
Read next
Related reading lists
Cite MapReduce
Dean, J., & Ghemawat, S. (2004). MapReduce: Simplified Data Processing on Large Clusters. USENIX OSDI.
@inproceedings{dean2004mapreduce,
title = {{MapReduce: Simplified Data Processing on Large Clusters}},
author = {Jeffrey Dean and Sanjay Ghemawat},
year = {2004},
booktitle = {USENIX OSDI},
url = {https://www.usenix.org/legacy/event/osdi04/tech/full_papers/dean/dean.pdf}
}Study MapReduce in ReadingTrack
Add the paper to your ReadingTrack library with its authors, venue and year, and get this page’s quiz as suggested review cards. You choose which cards to keep; nothing enters your reviews until you accept it.