Patterns
πŸ—ΊοΈ

Map-Reduce

Distributes computation across multiple nodes using map and reduce operations

Complexity: highParallelization

🎯 30-Second Overview

Pattern: Split data into chunks, process in parallel, then aggregate results

Why: Maximizes throughput, utilizes multiple cores/services, scales horizontally

Key Insight: Chunk[1..N] β†’ Map(f) β†’ [Result1..N] β†’ Reduce β†’ Final_Output

⚑ Quick Implementation

1Chunk:Split data into parallel-processable units
2Map:Apply same operation to each chunk
3Execute:Process chunks in parallel
4Reduce:Aggregate results into final output
5Validate:Check completeness & consistency
Example: documents β†’ [analyze, analyze, analyze] β†’ combine insights β†’ final_report

πŸ“‹ Do's & Don'ts

βœ…Ensure chunks are independent and balanced
βœ…Use deterministic reduce functions for consistency
βœ…Handle partial failures gracefully
βœ…Size chunks based on processing complexity
βœ…Cache map results for repeated reduce operations
❌Create chunks with interdependencies
❌Use non-commutative reduce operations
❌Ignore memory constraints with large datasets
❌Make chunks too small (overhead) or too large (imbalance)
❌Forget to handle empty or malformed chunks

🚦 When to Use

Use When

  • β€’ Large datasets to process
  • β€’ Independent, repeatable operations
  • β€’ CPU/IO bound tasks
  • β€’ Need horizontal scaling

Avoid When

  • β€’ Small datasets (overhead exceeds benefit)
  • β€’ Sequential dependencies
  • β€’ Memory-intensive aggregation
  • β€’ Real-time streaming needs

πŸ“Š Key Metrics

Throughput
Items processed per second
Parallelization Efficiency
% of ideal speedup achieved
Resource Utilization
CPU/memory usage across workers
Fault Tolerance
% of partial failures handled
Load Balance
Variance in chunk processing times
Cost Efficiency
Cost per processed item vs sequential

πŸ’‘ Top Use Cases

Document Analysis: Split large documents β†’ analyze sections β†’ combine insights
Content Moderation: Batch posts β†’ classify each β†’ aggregate violation reports
Data Validation: Chunk records β†’ validate each β†’ compile error summary
Sentiment Analysis: Split reviews β†’ analyze sentiment β†’ generate overall score
Code Analysis: Split codebase β†’ analyze files β†’ generate quality report

Pattern Relationships

Discover how Map-Reduce relates to other patterns

Prerequisites, next steps, and learning progression

Prerequisites

(1)
⛓️
Sequential Chaining
lowprompt chaining

Linear processing foundation that Map-Reduce parallelizes

πŸ’‘ Understanding linear processing helps design effective parallel decomposition

Next Steps

(3)
πŸ“‘
Scatter-Gather
mediumparallelization

More flexible parallel distribution with heterogeneous processing

πŸ’‘ Natural evolution when you need different operations on different data types

🍴
Fork-Join
mediumparallelization

Recursive parallel decomposition with work stealing

πŸ’‘ Advanced parallelization with dynamic load balancing

πŸ•ΈοΈ
Stateful Graph Workflows
very-highplanning execution

Complex parallel workflows with state management

πŸ’‘ Enterprise-grade parallel processing with sophisticated orchestration

Alternatives

(2)
⏳
Async-Await
lowparallelization

Promise-based concurrency without explicit chunking

πŸ’‘ Simpler approach when data doesn't need explicit partitioning

πŸ“‘
Scatter-Gather
mediumparallelization

More flexible distribution for heterogeneous tasks

πŸ’‘ Better when operations vary significantly across data items

Industry Applications

Financial Services

Large-scale parallel analysis for risk assessment and fraud detection

πŸ“ŠMulti-Criteria Decision Making
βš–οΈLLM-as-Judge

Content & Knowledge

Parallel processing of large document collections and knowledge bases

πŸ“šAdvanced RAG
πŸ—‚οΈHierarchical Planning

Software Development

Parallel code analysis and testing across large codebases

πŸ’»Code Execution
πŸ”§SWE-Bench Suite

References & Further Reading

Deepen your understanding with these curated resources

Contribute to this collection

Know a great resource? Submit a pull request to add it.

Contribute

Patterns

closed

Loading...

Built by Kortexya