DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • When Events Move Faster Than Your Database: A Resilient Design Pattern
  • Tactical Domain-Driven Design: Bringing Strategy to Code
  • Domain-Driven-Design With JPA: A Practical Guide
  • Architecture and Code Design, Pt. 2: Polyglot Persistence Insights To Use Today and in the Upcoming Years

Trending

  • Why Round-Robin Won't Save You: Load Balancing Challenges in Data Streaming Services With Heterogeneous Traffic
  • The Hidden Cost of AI Tokens: Engineering Patterns for 10x Resource Efficiency
  • Building a DevOps-Ready Internal Developer Platform: A Hands-On Guide to Golden Paths, Self-Service, and Automated Delivery Pipelines
  • Slopsquatting: Building a Scanner That Catches AI-Hallucinated Packages Before They Reach Production
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Four MapReduce Design Patterns

Four MapReduce Design Patterns

A look at the four basic MapReduce design patterns, along with an example use case.

By 
Shital Kat user avatar
Shital Kat
·
Mar. 27, 16 · Opinion
Likes (31)
Comment
Save
Tweet
Share
63.6K Views

Join the DZone community and get the full member experience.

Join For Free

Last article, I wrote about creating a simple word count program in MapReduce along with a tutorial to run the program using Hadoop. Please go through it if you are not aware of how to write a program in MapReduce.

To solve any problem in MapReduce, we need to think in terms of MapReduce. It is not necessarily true that every time we have both a map and reduce job.

MapReduce Design Pattern

  • Input-Map-Reduce-Output
  • Input-Map-Output
  • Input-Multiple Maps-Reduce-Output
  • Input-Map-Combiner-Reduce-Output

Following is a real time scenario to understand when to use which design pattern.

  • Input-Map-Reduce-Output

Image title

If we want to do some aggregation then this pattern is used:

Scenario

Counting gender total/ average salary of employees

Map (Key, Value)

Key: Gender

Value: Their Salary

Reduce

Group by Gender

And Take Total of salary for each group


  • Input-Map-Output

Input-Map-Output

If we want to change only the format of data then this pattern is used:

Scenario

Some employees have gender entry as “Female”, “F”,”f”,0

Map (Key, Value)

Key : Employee Id

Value : Gender ->

 if Gender is Female/ F/ f/ 0 then converted to F

else if Gender is Male/M/m/1 then convert to M

  • Input-Multiple Maps-Reduce-Output

Input-Multiple Maps-Reduce-Output

In this design pattern, our input is taken from two files which have a different schema:

Scenario

We have to find the total of gender-wide salary. But he have 2 files with different schema.

Input File 1

Gender is given as a prefix to Name

Eg. Ms. Shital Katkar

      Mr. Krishna Katkar


Input File 2

There is a different column for gender. However, the format is mixed.

Eg. Female/Male, 0/1, F/M

Map (Key, Value)

Map 1 (For input 1)

We need to write a program to split prefix from Name and, according to the prefix, determine the gender.

Then prepare the Key value pair (Gender,Salary).


Map 2 (For input 2)

Here the program will be straightforward. Resolve the mixed format and make a key value pair (Gender,Salary). 

Reduce

Group by Gender

And Take Total of salary for each group


  • Input-Map-Combiner-Reduce-Output

4.	Input-Map-Combiner-Reduce-Output

A Combiner, also known as a semi-reducer, is an optional class that operates by accepting the inputs from the Map class and thereafter passing the output key-value pairs to the Reducer class. Purpose of the combiner is to reduce workload of Reducer.

In MapReduce program, 20% of the work is done in the Map Stage, which is also known as the data preparation stage, which works in parallel.

80% of the work is done in Reduce stage which is known as the calculation stage, and it is not parallel. Therefore it is slower than the Map phase. To reduce time, some work in the Reduce phase can be done in the combiner phase.

Scenario

There are 5 departments. And we have to calculate the gender-wide total salary. However, there are certain rules to calculate the total. After calculating gender wise total for each department, if the salary is greater than 200K, add 20K in total, if the salary is greater than 100K,  add 10K in total

Input Files (for each department there is 1 file)

Map

(Parallel)

(, Value = Salary)

Combiner

(Parallel)

Reducer

(Not Parallel)

Output

Dept 1

Male<10,20,25,45,15,45,25,20>

Female <10,30,20,25,35>

Male <250,20>

Female <120,10>

Male

< 250,20,155,

10,90,90,30>


Female

<120,10,175,10,135,

10,110,10,130,10>


Male

<645>


Female

<720>

Dept 2

Male<15,30,40,25,45>

Female <20,35,25,35,40>

Male <155,10>

Female <175,10>

Dept 3

Male<10,20,20,40>

Female <10,30,25,70>

Male <90,00>

Female <135,10>

Dept 4

Male<45,25,20>

Female <30,20,25,35>

Male <90,00>

Female <110,10>

Dept 5

Male<10,20>

Female <10,30,20,25,35>

Male <30,00>

Female <130,10>

  • The points mentioned above are basic patterns. You can make you own as per requirement of the problem.
MapReduce Design Database

Opinions expressed by DZone contributors are their own.

Related

  • When Events Move Faster Than Your Database: A Resilient Design Pattern
  • Tactical Domain-Driven Design: Bringing Strategy to Code
  • Domain-Driven-Design With JPA: A Practical Guide
  • Architecture and Code Design, Pt. 2: Polyglot Persistence Insights To Use Today and in the Upcoming Years

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook