CDX-301e · Module 1
Map-Reduce & Competitive Execution
3 min read
Map-reduce applies the fan-out/fan-in pattern to data-parallel workloads. The map phase applies the same transformation to N independent inputs — analyzing N files, migrating N modules, testing N configurations. The reduce phase aggregates the N outputs into a single result — a summary report, a combined diff, a merged test matrix. Unlike ad-hoc fan-out, map-reduce is formulaic: one task template instantiated N times with different inputs, one aggregation function applied to all outputs.
Competitive execution is a fundamentally different pattern. Instead of splitting work across tasks, you give the same task to multiple agents and select the best result. Each agent approaches the problem independently — different algorithms, different architectures, different tradeoffs. You evaluate the candidates against your criteria (correctness, performance, readability, test coverage) and pick the winner. This is the pattern behind best-of-N: submit the same prompt N times, get N different implementations, choose the best one.
# Map-reduce: migrate all API route files to new pattern
MODULES=(auth payments users orders products inventory)
for m in "${MODULES[@]}"; do
codex cloud "migrate src/routes/${m}.ts to use ErrorEnvelope \
pattern. Only modify files in src/routes/${m}/" &
done
wait
# Reduce: merge all branches, run integration tests
codex cloud "merge all migration branches and run full test suite"
# Competitive: 3 approaches to a caching layer
for i in 1 2 3; do
codex cloud "design and implement a caching layer for \
the product catalog API. Use approach ${i} of 3: \
1=in-memory LRU, 2=Redis-backed, 3=HTTP cache headers" &
done
# Review all 3, pick the best
- Choose the right pattern Map-reduce for repetitive transformations across many inputs. Competitive execution for open-ended design decisions. Do not conflate them — they solve different problems.
- Template the map task Write one prompt template with a single variable (the input). Instantiate it N times. Consistency in the prompt ensures differences in output are due to the input, not prompt variance.
- Define selection criteria For competitive execution, define evaluation criteria before reviewing candidates. Without criteria, you will default to picking the first one that looks good.