Question 10 of 11 · CIE-2 QB · Set 2 · 6 marks
Open in ChatGPTIllustrate the MapReduce programming model and explain the functions of the Map and Reduce phases in distributed data processing.
Introduction
MapReduce is a programming model for processing very large data sets on a cluster, in which the programmer writes two functions and the framework handles distribution, partitioning, failure and communication. It was designed at Google and popularised by Hadoop.
The model
The input is a set of key-value pairs. The programmer supplies:
- map(k1, v1) → list(k2, v2): transforms each input record into intermediate pairs.
- reduce(k2, list(v2)) → list(v3): merges all intermediate values that share a key.
The framework groups all intermediate values by key between the two phases: this is the shuffle.
Execution
- The input is split into blocks, one per map task.
- Each mapper processes its split and writes intermediate pairs, partitioned by key (the number of reducers fixes the partition count).
- Each mapper sorts its partition locally and hands it to the reducers.
- The shuffle copies each key's pairs to the reducer responsible for that key.
- The reducer sorts by key, applies
reduceand writes the output to HDFS.
Diagram
Example: word count
- map: for each line, emit
(word, 1)for every word. - shuffle: all pairs for a word go to the same reducer.
- reduce: sum the list, emit
(word, total).
Why it scales
- Mappers run where the data is, so the network carries only intermediate pairs.
- The shuffle is a single sort and a single copy, so the cost is O(n log n).
- A failed task is simply re-executed, because map and reduce are pure functions of their input.
Conclusion
MapReduce trades a restricted programming model for automatic parallelism and fault tolerance. Its limitation is that every job pays the cost of one shuffle, which is why Spark keeps the model but keeps intermediate data in memory.