MapReduce: Simplified Data Processing on Large Clusters
Take away almost everything a program can say, and what is left can be parallelised, scheduled and re-run by a library nobody has to write twice.
Read the original ↗MapReduce is remembered as a way to process a lot of data. That undersells it: the contribution is that it let engineers who could not write a distributed system write one anyway, by taking away almost everything they could say.
The problem it was solving
The plain version of the idea is this. You have far more data than one machine can chew through, and a question about it that is genuinely simple, count how often each word appears, say. Write two small functions. The first, map, looks at one record at a time and emits labelled scraps: for the word count, it emits the word and the number one. The second, reduce, is handed one label and every scrap that was emitted under it, and boils them down: it adds the ones up. Between those two functions the framework does the only genuinely hard thing, which is gathering every scrap with the same label onto the same machine, and it does that without you writing a line of it. Why this still matters if you build systems: this paper is the clearest demonstration in the literature that taking power away from the person using your framework is what lets the framework do the difficult work on their behalf, and that argument transfers to job queues, request handlers and deployment pipelines long after the batch engine itself has been replaced.
The paper opens on an observation about its own authors' workplace rather than on a benchmark. Google had, by 2004, written hundreds of special-purpose programs over very large inputs: crawled documents, web request logs: producing derived things like inverted indices, summaries of pages crawled per host, and the most frequent queries of a day. Each of those computations is conceptually simple. What made them hard was everything wrapped around them.
That wrapping is the actual complaint. To run a simple computation over a lot of data you have to split the input, schedule work across machines, handle the machines that fail, handle the machines that are merely slow, move data to where it can be read cheaply, and deal with partial results. The paper's phrasing is that this obscures the original simple computation with large amounts of complex code, and the important word is obscures. The distributed-systems work was not just expensive, it was written fresh, by hand, next to every analysis anybody wanted to run.
So the target is not throughput. The target is the ratio of code that expresses the question to code that manages a cluster, and the paper's bet is that the second part can be written once, by specialists, if the first part is restricted enough to make it possible.
It helps to know what the machines looked like, because the model is shaped around one scarcity. Section 5 describes the cluster the measurements ran on: roughly 1800 machines, two 2 GHz processors and 4 GB of memory each, two commodity IDE disks apiece, gigabit ethernet per machine but arranged in a two-level switched tree with only about 100 to 200 gigabits per second of aggregate bandwidth available at the root. Do the division. Each machine can put a gigabit onto the wire, 1800 of them cannot, and the shortfall is an order of magnitude. So the network in the middle, not the disks and not the processors, is the resource the whole design is bending around, and every decision that looks fussy in the paper, scheduling a task on a machine that already holds its input, partially reducing map output before shipping it - is that one number being respected. A reader in an era of flat, fast datacenter fabrics should notice that this constraint is the one that has moved most since.
What it actually claims
MapReduce is a programming model plus one implementation of it. The model is borrowed openly, the paper credits the map and reduce primitives of Lisp and other functional languages, and the claim is not that the primitives are new but that they are the right restriction for a cluster.
The middle of the sandwich deserves stating precisely, because it is the part users never write and therefore never picture. The input is cut into M splits, typically 16 to 64 MB each so that a split is roughly one file-system block, and the output space is cut into R partitions. Each map task writes its emitted pairs into R local files, one per partition, chosen by a partitioning function that by default is a hash of the key taken modulo R. When a map task finishes it tells the master where those R files are, and the master passes the locations on to the reduce workers. A reduce worker then pulls its own partition's file from every one of the M map tasks, sorts what it collects so that equal keys are together, and calls the user's reduce function once per key. That pull step is the shuffle, and it is an all-to-all movement: M times R transfers, one per pair. Nothing else in the system is as expensive, and nothing else is as completely hidden from the person writing the job.
flowchart LR I1["input split 1"] --> M1["map task"] I2["input split 2"] --> M2["map task"] I3["input split 3"] --> M3["map task"] M1 --> R1["reduce for<br/>partition A"] M1 --> R2["reduce for<br/>partition B"] M2 --> R1 M2 --> R2 M3 --> R1 M3 --> R2 R1 --> O1["output file A"] R2 --> O2["output file B"]
The crossing edges in the middle are the shuffle, and they are the system. Every map task writes a piece for every reduce partition, so the traffic is the product of the two counts, not the sum. With the paper's own working sizes of 200,000 maps and 5,000 reduces that is a billion transfers, which is why the network was the thing being optimised.
- The model is two functions and nothing else
- A map function turns an input key/value pair into a set of intermediate key/value pairs. A reduce function takes one intermediate key and the whole set of values that were emitted under it, and produces a smaller set of values. That is the entire interface the user programs against. Everything in between, the grouping of values by key, which is where the work actually happens, belongs to the library and is not something the user can reach into.
- The restriction is what buys the fault tolerance
- Because a map task is a pure function of one input split, the framework may run it wherever it likes, and may run it again. A worker that dies takes its completed map output with it (that output sits on local disk), so those tasks are simply re-executed elsewhere. Completed reduce tasks are not re-executed, because their output is already in the distributed file system. The paper is explicit that this equivalence to a sequential run holds when the user's map and reduce operators are deterministic functions of their inputs, and it leans on atomic renames to commit a task's output exactly once.
- Stragglers are treated as a first-class failure
- A machine that is alive but slow: a failing disk, contention from another job, will hold up the entire computation, because the job ends when its last task does. The answer in the paper is backup tasks: near the end of a run, the master schedules duplicate executions of the tasks still in progress and takes whichever finishes first. This is one of the paper's most transferable observations, because a slow component is much harder to notice than a dead one and does far more damage at the tail of a job.
- Move the computation to the data
- The implementation is co-designed with GFS, and the master uses that: it knows where the replicas of each input block live, and tries to schedule a map task on a machine that already holds one, or failing that on a machine near one. Network bandwidth was the scarce resource, and this is the mechanism that stops most input from crossing the network at all.
- The refinements are the part that got it used
- The paper's later sections are unglamorous and matter enormously in practice: a combiner that partially reduces map output before it is shipped, a user-supplied partitioning function deciding which reducer a key lands on, counters, a status page, a mode that runs the whole job locally for debugging, and a facility to detect records that reliably crash the user's code and skip them. That last one is an admission worth noticing: at this scale, some of your input is simply poison, and a system that stops on it does not finish.
- The evidence is an in-house rewrite, not only a benchmark
- Alongside the sort and grep measurements, the paper reports rewriting Google's production indexing system on top of MapReduce, and argues the win in terms of the indexing code getting smaller and clearer and the pipeline getting easier to operate and to change. That is the claim the paper is really making, and it is a claim about engineers rather than about machines.
- How many tasks, and why the answer is so much larger than the machine count
- Section 3.5 is a short passage that explains more about the design than the architecture diagram does. Tasks are made far smaller than machines: the paper says it commonly runs with 200,000 map tasks and 5,000 reduce tasks across 2,000 worker machines, which is a hundred map tasks per machine. That is deliberate, and it buys two things. Load balances itself, because a fast machine simply takes more tasks. And a machine that dies leaves at most a task's worth of work to redo, spread across many other machines rather than dumped on one. The cost is paid by the master, which makes on the order of M plus R scheduling decisions and holds on the order of M times R pieces of state, at roughly one byte per map-and-reduce pair. Multiply the paper's own working numbers and that is about a gigabyte of bookkeeping on one coordinator. The upper bound on task granularity is not the workers. It is how much the master can remember.
- The experiment that carries the argument is the one where they break it on purpose
- Section 5 sorts a terabyte, ten billion hundred-byte records, with 15,000 map tasks and 4,000 reduce tasks, and the interesting result is not the time. A normal run finishes in 891 seconds. The same run with the backup-task mechanism switched off takes 1283 seconds, about 44 percent longer, and figure 3 shows why: a long tail of a few stragglers with nothing else happening, the cluster idle and waiting. Then they kill 200 of the 1746 worker processes mid-run, and the job finishes in 933 seconds, roughly 5 percent over normal. Read those three numbers together and the paper's real claim is visible. Losing eleven percent of the cluster outright costs almost nothing, and a handful of machines being merely slow costs eight times as much. That is the most useful thing in the paper, and it took an experiment rather than an argument to establish it.
- What it looked like in production, counted
- Section 6 publishes a month of usage rather than a case study, and the table is worth reading line by line. In August 2004 there were 29,423 jobs, using 79,186 machine-days, reading 3,288 terabytes of input and producing 758 terabytes of intermediate data to write 193 terabytes of output. The average job used 157 worker machines and took 634 seconds. Two lines in that table are the argument of the whole paper. There were 426 distinct map-and-reduce combinations in use, meaning several hundred separate analyses that nobody had to write a distributed system for. And the average job saw 1.2 worker deaths, which means the median engineer's job survived a machine failure without the engineer ever finding out, in code they wrote as two ordinary functions.
The one idea worth stealing
A framework can only recover work it understands, so the useful move is to take capability away from the user until the framework understands everything.
This is the inversion at the centre of the paper, and it is easy to read past because giving up expressiveness feels like a loss. It is not a loss here: it is the purchase price. Restricting the user to a pure function over one partition of the input is exactly what makes it safe to run that function twice, or on a different machine, or a fifth time because the fourth was slow. None of the fault tolerance is bolted on afterwards. It is available because the shape of the computation was constrained first.
The general form: when you are designing something other people will build on, ask what you would have to forbid in order to make recovery, retries and scheduling the platform's problem rather than theirs. Most APIs are designed the other way round, every capability the author could think of, and then a document explaining what the user must be careful about. Careful is not a mechanism.
The second thing worth taking is the treatment of slowness as a failure mode with its own remedy. Systems get monitoring for dead things almost automatically, and a machine that answers correctly but late will quietly set the pace of everything that waits on it. Backup tasks are one answer. The transferable part is having any answer at all.
There is a corollary about where to put your engineering, and the shuffle is the demonstration of it. Map and reduce are the parts the user writes and they are trivial. The grouping in between is the part the user never sees and it is the entire product. When you build a platform, find the one step that everybody would otherwise implement themselves, badly, and take it away from them completely: not wrap it in a helper, not document it well, but make it structurally impossible to write. The measure of whether you have done that is whether anybody can tell you how it works. Users of this system could not describe the shuffle, and that was the point.
The last habit to steal is how the paper defends itself: by breaking its own system on camera. It does not claim resilience, it kills 200 workers during a measured run and publishes the difference, and it does not claim backup tasks help, it turns them off and shows the 44 percent. If you are asserting that your system tolerates something, the demonstration is a run with the thing actually happening and a number next to a run without it. Anything less is a design document with confidence in it.
What aged badly
The model was right about the problem it named and wrong about how long that would be the shape of the problem. Most of what follows is the field, and Google, moving past it.
- One pass is not enough, and the shape forces a round trip through disk
- Map, shuffle, reduce is a single pass. Anything iterative: graph algorithms that walk the same structure repeatedly, most machine learning: becomes a chain of separate jobs, and between every pair of jobs the intermediate result is written to the distributed file system, replicated, and read back. For a job whose working set would have fit in memory across the cluster, that is the dominant cost and it is paid on every iteration. This is precisely the gap Spark's resilient distributed datasets attacked years later, and it is the reason a generation of pipelines moved off the model. Worth being clear that this is later work: the 2004 paper does not propose in-memory sharing and does not claim to.
- Google itself moved on, publicly
- Later Google work replaced both the interface and the engine. Higher-level pipeline layers arrived so that a chain of stages could be written as one program and optimised into an execution plan rather than hand-assembled from jobs. The batch indexing pipeline the paper cites as its proof was itself later replaced by incremental processing, so that a changed page could be folded into the index without rebuilding it. When the paper's own flagship application stops being run this way, the honest reading is that the model fit a particular era of the problem rather than the problem.
- The restricted model was, for most users, the wrong interface
- The paper's argument is that map and reduce are simple enough for any engineer. In practice most jobs people wrote were joins, filters, groupings and aggregations, relational work, and expressing those as hand-written map and reduce functions turned out to be more painful than writing them in a query language. The open-source ecosystem's response was a stack of layers whose purpose was to stop you writing MapReduce by hand, and eventually engines that did not use the model underneath at all. The enabling constraint was real. The specific interface was not the one most people wanted to hold.
- The name detached from the paper
- "MapReduce" came to mean batch processing in general, and often specifically the Hadoop stack, which is an independent open-source implementation and not what this paper describes. The paper never claims to be a general answer for large-scale data processing, never mentions streaming, and never argues that batch is the right latency for anything: it describes one model, its implementation, and where it was used. Almost every criticism aimed at "MapReduce is dead" is aimed at the name.
- Checkpointing everything is only worth it at the size that justifies it
- Writing every intermediate result to disk so that any task can be re-run is a good trade when a job runs for hours across enough machines that something will certainly fail during it. It is a bad trade for a job that would finish in minutes on a handful of machines, where the durability machinery is most of the runtime. A great deal of mid-2010s data engineering was people paying cluster-scale overheads for problems that had stopped being cluster-scale.
- The shuffle grows as a product, and that is the wall
- Everything the model gives you is bought with an all-to-all data movement whose size is the number of map tasks multiplied by the number of reduce tasks. The paper's own sort runs 15,000 by 4,000, which is 60 million transfers for one terabyte. Its stated working configuration of 200,000 by 5,000 is a billion. Add a machine and both factors tend to rise, so the coordination cost rises faster than the capacity does. Everything unpleasant about operating systems of this lineage lives here: small intermediate files by the million, a reduce phase that cannot start until enough maps have finished, one skewed key that lands a hundred times more data on one reducer than the others, and none of it is visible in the programming model, which is exactly why it surprises people. The paper mentions the partitioning function and the combiner as the levers, and they are the right levers, but it does not dwell on how much of a practitioner's life is spent pulling them.
- Determinism is load-bearing, and user code violates it constantly
- The equivalence between a distributed run and a sequential one holds only when the user's map and reduce functions are deterministic functions of their inputs, and the paper says so plainly and then works through the weaker guarantee you get when they are not. In practice the functions people write are not deterministic nearly as often as they believe: they read the clock, they generate an identifier, they call an external service, they iterate a hash map whose order is not fixed. Re-run such a task after a machine dies and the output changes, quietly, with every mechanism in the system reporting success, because the framework's whole recovery story is built on being allowed to run your function again. This is the same failure that makes statement-based database replication unsafe, and it is the single most common way a correct-looking pipeline produces two different answers for the same input on two different days.
- What to take from it today
- Nobody should write a map and a reduce function by hand in this decade, and that is fine, because the paper's value was never the interface. Take three things. First, the trade: decide what to forbid so that retries, scheduling and recovery become your framework's problem rather than every user's, and understand that the expressiveness you give up is the price rather than a regret. Second, the tail: a component that is slow is more damaging than a component that is dead, it will not show up in your alerting, and having any deliberate answer for it - a duplicate attempt, a hedged request, a timeout with a second try, beats having none. Third, the standard of evidence: kill something during the measured run and publish both numbers. The engine was replaced within a decade by systems that keep data in memory between stages. Those three ideas were not.
Related on chalk
The same idea as a board, lab, video or lesson.
- BoardBatch Processingthe chapter this paper started, with the model taken apart
- BoardThe Inverted Indexthe paper's own worked example, building one is the job MapReduce was written for
- BoardStorage & Compute Infrathe fleet underneath, and what replaced this pipeline on it
- BoardSplitting the Ledgerthe partitioning function that decides which reducer a key lands on, and the hot key that stalls one
- BoardConcurrency and the Hardwarewhy 'run it on more machines' stops helping, which is the ceiling on the whole promise
- LabThe parallel ceilingmove the sequential fraction and watch the speedup ceiling refuse to move with it
- LabSplitting the ledgera badly chosen key sends most of the work to one worker, the straggler reducer, run
- LabHow cost growsparallelism moves the constant, never the exponent: a bad algorithm at scale is still bad
- VideoThe data platform: how a change proves itself before it shipsa batch pipeline and the faster path beside it, which is the shape this model became
- VideoSharding: splitting the ledgerpartition by key, and the hot shard that does everyone's work
- LessonBatch ProcessingUses the board Batch Processing
- LessonFrom raw to trusted: ETL, ELT and the data pipelineUses the board Batch Processing
- LessonP5: A pipeline from raw to dashboardUses the board Batch Processing
- LessonGoogle Search, the case studyUses the board The Inverted Index
- LessonKV: the ringUses the board Splitting the Ledger
- LessonSplitting the ledger (sharding)Uses the board Splitting the Ledger
- LessonChanging the engine in flight (live schema and data migrations)Uses the board Splitting the Ledger
- LessonConcurrency & the HardwareUses the board Concurrency and the Hardware
- LessonWaiting without spinningUses the board Concurrency and the Hardware
- LessonFour ways to get stuck: deadlockUses the board Concurrency and the Hardware
- LessonOne key, many handsUses the board Concurrency and the Hardware
- LessonWho sees your write first: memory orderingUses the board Concurrency and the Hardware
Further reading
Read the original for the full argument and its evidence.
- The paper (PDF) ↗OSDI 2004. Section 3 is the implementation and section 3.6 is backup tasks. Section 5's list of what it was used for is more revealing than the benchmarks.
- Resilient Distributed Datasets (PDF) ↗Later work, and the direct reply: Spark's NSDI 2012 paper, whose motivation section is an argument about exactly the between-stages disk round trip above.