Vengeance Blog

MapReduce Explained Simply

How map and reduce scale batch processing across machines.

Systems Notes1 minInspired by Dean & Ghemawat (2004)

Core idea

MapReduce separates user logic from distributed execution. You define map/reduce, the runtime handles partitioning, scheduling, shuffle, and retries.

Map phase

Map reads input records and emits key/value pairs in parallel.

tsx
1function map(docId, text) {2  for (const word of tokenize(text)) emit(word, 1);3}

Shuffle

All values for the same key are grouped and moved to reducers. This is often the most expensive phase.

Reduce phase

Reducers aggregate grouped values.

tsx
1function reduce(word, counts) {2  emit(word, sum(counts));3}