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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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
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

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Architecture and Code Design, Pt. 2: Polyglot Persistence Insights To Use Today and in the Upcoming Years
  • Design to Support New Query Parameters in GET Call Through Configurations Without Making Code Changes
  • How to Design a CRUD Web Service for Inheritable Entity
  • Session State Design Patterns in Java: Client, Server, and Database Session State Design Patterns

Trending

  • Operational Principles, Architecture, Benefits, and Limitations of Artificial Intelligence Large Language Models
  • Using Python Libraries in Java
  • Next Evolution in Integration: Architecting With Intent Using Model Context Protocol
  • Building Reliable LLM-Powered Microservices With Kubernetes on AWS
  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.3K 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

  • Architecture and Code Design, Pt. 2: Polyglot Persistence Insights To Use Today and in the Upcoming Years
  • Design to Support New Query Parameters in GET Call Through Configurations Without Making Code Changes
  • How to Design a CRUD Web Service for Inheritable Entity
  • Session State Design Patterns in Java: Client, Server, and Database Session State Design Patterns

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!