Skip to content
tezvyn:
Menu

MapReduce: Divide and Conquer for Big Data

Source: Wikipedia: MapReduceEasyHow cards are made

MapReduce breaks a huge data job into smaller, parallel tasks across a cluster. It's ideal for batch processing massive datasets, like indexing the web. The common footgun is using it for real-time queries; it's built for throughput, not speed.

Why it exists

Processing datasets that are too large to fit on a single machine is slow and complex. MapReduce was created to provide a simple model for running distributed computations on clusters of commodity hardware, hiding the complexity of parallelism, fault tolerance, and data distribution from the developer.

The mental model

Imagine you need to count every word in a massive library. You can't do it alone. MapReduce is like hiring thousands of assistants. First, you give each assistant a single book (the 'Map' phase) and tell them to count the words in it. Then, you collect all their individual counts and add them together (the 'Reduce' phase) to get the final total. The framework handles assigning books, noticing if an assistant gets sick, and managing the final tally.

How it works

Based on its name, a MapReduce job has two main phases. First, the 'Map' phase takes a large input dataset, splits it into independent chunks, and processes them in parallel across the cluster. Each map task outputs intermediate key-value pairs. The framework then automatically 'shuffles' and sorts this intermediate data, grouping all values associated with the same key. Second, the 'Reduce' phase takes these grouped key-value lists and processes them, also in parallel, to produce the final result. The system handles all the hard parts: distributing work, re-running failed tasks, and moving data between machines.

When to use it

Use MapReduce for large-scale, batch-oriented data processing tasks that can be easily parallelized. It excels at jobs like log analysis, data warehousing queries, and building inverted indexes for search engines. The key is that the job is not time-sensitive and can run for minutes or hours to achieve high throughput on terabytes or petabytes of data.

When not to use it

Avoid MapReduce for low-latency, real-time data processing. It's not suitable for interactive queries or streaming applications where you need an answer in seconds or milliseconds. The overhead of scheduling jobs and moving data makes it inefficient for small tasks or complex, multi-stage pipelines where modern frameworks like Apache Spark are often a better fit.

One canonical example

The classic 'word count' is the 'Hello, World!' of MapReduce. Given a massive collection of text documents, a Map task would read a document and output a key-value pair for each word (e.g., <'the', 1>). The framework then shuffles and sorts these pairs. A Reduce task then receives a key and a list of all its associated values (e.g., <'the', [1, 1, 1, ...]>), sums them up, and outputs the final count (e.g., <'the', 54321>).

Interview question

For which data processing scenario is MapReduce generally considered LEAST effective?

  • a.Analyzing historical log data from billions of events for daily reports
  • b.Aggregating large volumes of financial transactions for end-of-day reconciliation
  • c.Generating an inverted index for a web-scale search engine
  • d.Providing immediate responses to interactive user queriesCorrect
Why?

MapReduce is designed for high-throughput batch processing of massive datasets, not for low-latency, real-time interactive queries. The overhead of scheduling jobs and moving data makes it inefficient for immediate responses, which is a common misconception for beginners.

Just read this? Test yourself on what you have been reading.

Read the original → en.wikipedia.org

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles