Map-Reduce

Map over chunks. Reduce to one answer.

A large task is mapped over independent chunks and subsequently aggregated or reduced into a single result.

Level
02 · Workflow
Also known as
Fan-out/Fan-in, Map Aggregate, Batch Decomposition
Trade-off
Excellent scaling capabilities are achieved against the risk of generating inconsistent partial results.
Native in
LangGraph, AWS Strands, Google ADK, Microsoft Agent Framework
The effect

What it actually does.

Input is split, mapped in parallel, then reduced.

inputchunk 1chunk 2chunk 3reduce
Walk it through

A real run, step by step.

Task“What are the most frequent complaints in these 300 customer reviews?” The reviews do not fit into one call:
Illustrative run. With 3,000 reviews the map stage makes 60 calls and nothing else changes.
StageInputCallsOutput
Split300 reviews06 chunks of 50 reviews
MapOne chunk per call6Per chunk, a list of complaints with counts
ReduceThe 6 partial lists1One ranked list for all 300 reviews
What this shows: every map call is the same step on a different chunk, and no call knows about the others. That is why the stage scales with the input. It is also the weak point: one chunk says “late delivery”, another “shipping delay”, and only the reduce step can see that both mean the same thing.
In code

The pattern in code.

Plain Pythonpython
from concurrent.futures import ThreadPoolExecutor

def top_complaints(reviews, chunk_size=50):
    chunks = [reviews[i:i + chunk_size] for i in range(0, len(reviews), chunk_size)]
    with ThreadPoolExecutor() as pool:
        # map: the same call for every chunk
        partials = list(pool.map(extract_complaints, chunks))
    # reduce: one call over the partial lists
    return merge_and_rank(partials)
Fit

Use it, or not.

When to reach for it

  • Large inputs can be split into independent chunks.
  • Aggregation logic is clearly definable.
  • Throughput scalability is critical.

When it backfires

  • Global dependencies exist between chunks.
  • The reduction would lose semantic value.
  • A central context is required.
Pitfalls

Two ways this pattern will hurt you.

Reducer loses cross-chunk context

The reducer only sees per-chunk outputs and misses relationships that span chunk boundaries.

Countermeasure

Include chunk metadata (position, overlap) in mapper output, or use a two-pass reducer that first reconciles boundaries.

Uneven chunk sizes overload one mapper

One chunk is 10x larger than the others. Its mapper dominates latency and the whole job waits.

Countermeasure

Use dynamic chunk sizing or a size-aware splitter that balances load across mappers.

Framework support

Where Map-Reduce is native.

LangGraphSend API map + reduceNative
AWS Strandsparallel map stepsNative
Google ADKparallel agentsNative
Microsoft Agent Frameworkfan-out / fan-inNative

Search

Search patterns, frameworks, and pages.