Skip to main content

MapReduce Programming Model

Module Duration: 5-6 hours Hands-on Projects: 8 coding exercises Prerequisites: Java programming, HDFS basics from Module 2

Introduction

MapReduce is the programming paradigm that made distributed computing accessible to developers. By providing a simple abstraction (map and reduce functions), it hides the complexity of:
  • Parallelization
  • Fault tolerance
  • Data distribution
  • Load balancing
In this module, you’ll write production-quality MapReduce code and master optimization techniques.

The MapReduce Paradigm

Core Concept

All MapReduce programs follow this pattern:
Map Phase: Transform input records into intermediate key-value pairs Shuffle Phase: Group all values by key (framework handles this) Reduce Phase: Process each group to produce final output

Classic Example: WordCount

Running the Job:

MapReduce Execution Flow

Job Submission and Task Execution

InputSplit vs HDFS Block

Key Point: One InputSplit = One Map Task
  • Framework tries to align splits with HDFS blocks for data locality
  • Text splits may span blocks slightly to avoid breaking lines

Advanced MapReduce Patterns

Pattern 1: Filtering

Extract records matching criteria.

Pattern 2: Summarization (Aggregation)

Compute summary statistics.

Pattern 3: Joins (Reduce-Side Join)

Join two datasets on a common key.

Pattern 4: Secondary Sort

Control the order of values arriving at reducer.

Optimization Techniques

Combiner Functions

Reduce shuffle data volume by pre-aggregating on map side.
Impact:
When to Use: Function must be commutative and associative
  • ✅ Sum, Count, Max, Min
  • ❌ Average (use sum + count instead), Median

Custom Partitioners

Control which reducer receives which keys.

Distributed Cache

Share read-only data across all tasks.

Counters and Monitoring

Track job statistics and custom metrics.

Unit Testing MapReduce

Test your map and reduce functions independently.

Common Pitfalls

Anti-Pattern 1: Not Reusing Objects
Anti-Pattern 2: Skewed Keys

Interview Focus

Key Questions:
  1. “Explain shuffle and sort phase”
    • Map output partitioned by key hash
    • Sorted by key
    • Transferred to reducers over network
    • Merged and grouped before reduce
  2. “When would you use a combiner?”
    • Reduce shuffle traffic
    • Function must be associative + commutative
    • Example: SUM yes, AVERAGE no (without modification)
  3. “How to optimize a slow MapReduce job?”
    • Add combiner
    • Increase parallelism (more mappers/reducers)
    • Use compression
    • Fix data skew
    • Optimize code (reuse objects)

What’s Next?

Module 4: YARN Resource Management

Learn how YARN manages cluster resources and schedules applications