Split a huge job into small map tasks and then combine the results with reduce tasks.
MapReduce is a way to process a huge amount of data by cutting the job into small pieces that run on many machines at the same time, and then combining the results.
Imagine a file so big that one computer would need days to read it. The idea of MapReduce is simple: split the file, let many computers each work on a piece, and then merge what they found. The hard parts (splitting, moving data, restarting a failed machine) are handled by the framework, so the programmer writes only two small functions.
The classic example is a word count. The map function reads a line and emits (word, 1) for every word. The framework then groups the pairs by word (shuffle and sort). The reduce function receives a word and the list of its 1s, and adds them up.
The model was made well known by a Google paper, and the open-source Hadoop brought it to everyone. Today newer engines (such as Spark) are used more often, but they keep the same core idea: move the computation to the data, process pieces in parallel, and group by key.
| Step | What it does | Where it runs |
|---|---|---|
| Input split | Cut the input into pieces, usually matching file blocks | Framework |
| Map | Turn each record into zero or more (key, value) pairs | On many machines, near the data |
| Combine (optional) | A reduce that runs on one mapper's output, to cut data before the shuffle | On the mapper machine |
| Partition | Choose the reducer for each key, often hash(key) modulo the number of reducers | On the mapper machine |
| Shuffle and sort | Move pairs across the network and group them by key | Between machines |
| Reduce | Combine all values of one key into a result | On many machines, one key group at a time |
| Output | Write the result, often to a distributed file system | Reducers |
| Job | Map emits | Reduce does |
|---|---|---|
| Word count | (word, 1) | Sum the 1s |
| Page views per URL | (url, 1) from each log line | Sum per URL |
| Maximum temperature per city | (city, temperature) | Keep the largest value |
| Inverted index | (word, document id) | Collect the list of documents |
| Join two tables | (join key, row tagged with its table) | Pair rows from both tables for the same key |
A teaching model: tiny inputs, a simple hash for the partition, and no failures or disk. A real framework also writes map output to local disk, retries failed tasks and moves the code to the data.
| Term | Meaning in easy words |
|---|---|
| Map | A step that turns each input record into (key, value) pairs |
| Reduce | A step that combines all values for one key into a result |
| Shuffle | Moving pairs across the network so that all pairs of one key meet |
| Combiner | A mini reduce on the mapper side that shrinks data before the shuffle |
| Partitioner | The rule that picks the reducer for a key, often a hash |
| Split | A piece of the input that one mapper works on |
| Mapper / Reducer | A task (or the machine slot) running the map or reduce function |
| Data skew | One key has much more data than the others, so one reducer is overloaded |
| Straggler | A task that runs much slower than the rest and delays the job |
| Speculative execution | Starting a copy of a slow task on another machine and using whichever finishes first |
| Hadoop | An open-source system with a distributed file system (HDFS) and a MapReduce engine |
| Choice | We gain | We lose |
|---|---|---|
| Disk-based MapReduce | Strong fault tolerance on huge jobs | Slow, especially for jobs with many stages |
| In-memory engine (Spark style) | Much faster for iterative and interactive work | More memory needed, and recovery needs more care |
| More reducers | More parallel work in the final step | More small output files and more tasks to manage |
| Using a combiner | Much less data in the shuffle | Only valid for operations that can be done in parts |
| Batch MapReduce | Simple, cheap, handles any size | Results are late: minutes or hours old |
| Stream processing instead | Results within seconds | A harder system to build and run |