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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  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.

Shital Kat user avatar by
Shital Kat
·
Mar. 27, 16 · Opinion
Like (31)
Save
Tweet
Share
61.84K 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.

Popular on DZone

  • Low-Code Development: The Future of Software Development
  • Getting a Private SSL Certificate Free of Cost
  • Authenticate With OpenID Connect and Apache APISIX
  • Simulating and Troubleshooting BLOCKED Threads in Kotlin [Video]

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: