Orchestration pattern for large-scale processing where work is distributed, processed independently, then combined. Map phase splits and processes, Reduce phase aggregates results...
Trigger when:
Do NOT trigger for:
MAP PHASE REDUCE PHASE
ββββββββββββββ
β Process A ββββ Result A ββ
[All Items] ββββββββββββββ€ β βββββββββββββββ
β β Process B ββββ Result B ββΌβββ β Aggregate ββββ [Final]
β ββββββββββββββ€ β βββββββββββββββ
βββSplitββ Process C ββββ Result C ββ
ββββββββββββββ€
β Process D ββββ Result D ββ
ββββββββββββββ
Specify what you're processing:
Map-Reduce Job: [Name]
Input: [What collection of items]
Map function: [What to do to each item]
Reduce function: [How to combine results]
Expected output: [What the final result looks like]
List everything to process:
Items to process:
1. [Item 1] - [brief description]
2. [Item 2] - [brief description]
3. [Item 3] - [brief description]
...
Total: [N] items
For large sets, use patterns:
Items: All files matching src/**/*.ts
Count: ~150 files
Batching: Groups of 10
Process each item (parallel when possible):
βββββββββββββββββββββββββββββββββββββββ
MAP PHASE: Processing [N] items
βββββββββββββββββββββββββββββββββββββββ
Batch 1 (items 1-10):
[Processing...]
- Item 1: [Result]
- Item 2: [Result]
...
Batch 2 (items 11-20):
[Processing...]
...
Map phase complete: [N] items processed
- Succeeded: [X]
- Failed: [Y]
- Skipped: [Z]
Gather all map outputs:
Intermediate results:
ββββββββββββ¬ββββββββββββββββββββββββββββββ
β Item β Map Result β
ββββββββββββΌββββββββββββββββββββββββββββββ€
β Item 1 β [Result summary] β
β Item 2 β [Result summary] β
β ... β ... β
ββββββββββββ΄ββββββββββββββββββββββββββββββ
Aggregate results:
βββββββββββββββββββββββββββββββββββββββ
REDUCE PHASE: Aggregating results
βββββββββββββββββββββββββββββββββββββββ
Reduction strategy: [How combining]
Aggregating...
Categories identified:
- Category A: [N] items
- Category B: [M] items
Statistics:
- Total processed: [X]
- Issues found: [Y]
- Patterns detected: [Z]
Present combined results:
βββββββββββββββββββββββββββββββββββββββ
MAP-REDUCE COMPLETE: [Job Name]
βββββββββββββββββββββββββββββββββββββββ
## Summary
[High-level findings]
## Statistics
- Items processed: [N]
- [Metric 1]: [Value]
- [Metric 2]: [Value]
## Categories/Groups
[Breakdown by category]
## Notable Items
[Specific items worth highlighting]
## Recommendations
[Actions based on findings]
By directory:
Items: All TypeScript files
Batches: src/api/*, src/components/*, src/utils/*
By type:
Items: All source files
Batches: *.ts, *.tsx, *.css
Adaptive:
Start with batch of 20
If too slow β reduce to 10
If fast β increase to 30
User: "Check all API endpoints for authentication issues"
Map-Reduce Job: API Security Audit
Input: All files in src/api/**/*.ts
Map function: Check each file for auth patterns
Reduce function: Group by issue severity
βββββββββββββββββββββββββββββββββββββββ
MAP PHASE: Processing 23 files
βββββββββββββββββββββββββββββββββββββββ
- users.ts: [Missing rate limit on /login]
- orders.ts: [No auth on /history endpoint]
- products.ts: [Clean]
- admin.ts: [Deprecated auth method]
...
βββββββββββββββββββββββββββββββββββββββ
REDUCE PHASE: Aggregating results
βββββββββββββββββββββββββββββββββββββββ
By severity:
- Critical: 2 files (orders.ts, payments.ts)
- Warning: 5 files
- Clean: 16 files
βββββββββββββββββββββββββββββββββββββββ
MAP-REDUCE COMPLETE: API Security Audit
βββββββββββββββββββββββββββββββββββββββ
Summary: 7 of 23 endpoints have auth issues
Critical (fix immediately):
1. orders.ts:45 - GET /history has no auth check
2. payments.ts:23 - POST /refund missing admin check
Recommendations:
1. Add auth middleware to orders router
2. Implement admin check on payments
User: "How complex is our codebase? Get metrics on all files."
Map-Reduce Job: Codebase Complexity Analysis
Input: All source files
Map function: Count lines, functions, cyclomatic complexity
Reduce function: Aggregate statistics, find outliers
βββββββββββββββββββββββββββββββββββββββ
MAP PHASE: Processing 234 files
βββββββββββββββββββββββββββββββββββββββ
[Batched processing of all files...]
βββββββββββββββββββββββββββββββββββββββ
REDUCE PHASE: Aggregating results
βββββββββββββββββββββββββββββββββββββββ
Totals:
- Lines of code: 45,230
- Functions: 1,847
- Average complexity: 4.2
Distribution:
- Low complexity (<5): 78%
- Medium (5-10): 18%
- High (>10): 4%
βββββββββββββββββββββββββββββββββββββββ
MAP-REDUCE COMPLETE
βββββββββββββββββββββββββββββββββββββββ
Notable outliers (high complexity):
1. src/utils/parser.ts - complexity 23
2. src/api/legacy/converter.ts - complexity 19
Recommendations:
Consider refactoring top 5 complex files.
User: "Convert all class components to functional components"
Map-Reduce Job: Class β Functional Conversion
Input: All React component files
Map function: Convert class to functional if applicable
Reduce function: Track conversions, summarize changes
βββββββββββββββββββββββββββββββββββββββ
MAP PHASE
βββββββββββββββββββββββββββββββββββββββ
- Header.tsx: Converted (was class)
- Button.tsx: Already functional (skipped)
- Modal.tsx: Converted (was class)
- LegacyForm.tsx: Cannot convert (uses getDerivedStateFromProps)
...
βββββββββββββββββββββββββββββββββββββββ
REDUCE PHASE
βββββββββββββββββββββββββββββββββββββββ
Summary:
- Converted: 34 components
- Already functional: 56 components
- Cannot convert: 3 components
- Failed: 1 component
Changes made to 34 files.
"Check everything" is easy to say, hard to do well. Without structure, you get incomplete coverage, inconsistent analysis, and no useful summary.
Map-Reduce brings discipline to bulk operations: every item processed uniformly, failures tracked, results aggregated meaningfully. It's the difference between "I looked at some files" and "I analyzed all 234 files, here's what I found."
Scale requires structure. This is that structure.