Data lake design patterns in Hadoop - Time & Space Complexity
When working with data lakes, it is important to understand how the time to process data grows as the data size increases.
We want to know how the design pattern affects the speed of data processing in Hadoop.
Analyze the time complexity of the following Hadoop MapReduce job using a data lake design pattern.
// Mapper reads data from raw zone
map(key, value) {
// parse and filter records
if (record is valid) {
emit(key, value);
}
}
// Reducer aggregates filtered data
reduce(key, values) {
sum = 0;
for each v in values {
sum += v;
}
emit(key, sum);
}
This code reads raw data, filters it, and then aggregates results in the reduce step.
Look at the loops and repeated steps in the code.
- Primary operation: The reducer loops over all values for each key to sum them.
- How many times: The reducer runs once per unique key, processing all associated values.
As the input data grows, the number of records to process grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 map operations and sums over small groups |
| 100 | About 100 map operations and sums over larger groups |
| 1000 | About 1000 map operations and sums over even larger groups |
Pattern observation: The total work grows roughly in direct proportion to the input size.
Time Complexity: O(n)
This means the time to process data grows linearly as the data size increases.
[X] Wrong: "The reducer runs a fixed number of times regardless of data size."
[OK] Correct: The reducer runs once per unique key, so if data grows with more keys or values, the reducer work grows too.
Understanding how data lake design patterns affect processing time helps you explain how to handle big data efficiently in Hadoop.
"What if we added a combiner step before the reducer? How would the time complexity change?"
Practice
Solution
Step 1: Understand the role of data zones
Raw, processed, and curated zones help organize data by its state and quality.Step 2: Identify the benefit of this organization
This organization keeps data clean, easy to find, and ready for analysis.Final Answer:
To keep data clean, easy to find, and ready for analysis -> Option BQuick Check:
Data zones improve data usability = A [OK]
- Confusing size increase with organization benefits
- Assuming data zones restrict access
- Thinking zones reduce user numbers
Solution
Step 1: Recall standard folder naming for data zones
The raw data zone is usually stored in a folder named 'raw' to indicate unprocessed data.Step 2: Match folder names to zones
/data/raw/ matches the raw data zone, while others represent different zones or purposes.Final Answer:
/data/raw/ -> Option CQuick Check:
Raw data folder = /data/raw/ [OK]
- Choosing processed or curated folder names for raw data
- Using unrelated folder names like analytics
- Confusing folder names with data types
/data/raw/sales.csv
/data/processed/sales_clean.csv
/data/curated/sales_summary.csv
Which file would most likely contain cleaned and transformed sales data ready for analysis?
Solution
Step 1: Understand the meaning of each zone
Raw zone has original data, processed zone has cleaned/transformed data, curated zone has aggregated or summarized data.Step 2: Identify the file with cleaned and transformed data
/data/processed/sales_clean.csv indicates cleaned sales data ready for further use.Final Answer:
/data/processed/sales_clean.csv -> Option AQuick Check:
Processed zone = cleaned data = D [OK]
- Choosing raw data file as cleaned data
- Confusing curated summary with cleaned data
- Selecting non-existent file paths
/data/raw/, /data/processed/, and /data/curated/. You accidentally saved uncleaned data in /data/curated/. What is the best fix?Solution
Step 1: Identify the problem with data placement
Uncleaned data should not be in the curated zone, which is for clean, ready data.Step 2: Choose the correct fix
Moving uncleaned data back to raw zone and reprocessing it ensures proper data flow and quality.Final Answer:
Move the uncleaned data to/data/raw/and reprocess it -> Option AQuick Check:
Raw zone = uncleaned data fix = B [OK]
- Ignoring data quality rules
- Deleting unrelated folders
- Renaming folders without moving data
Solution
Step 1: Understand the goal of fast analytics and governance
Fast analytics needs clean, organized data; governance needs clear structure and control.Step 2: Identify the best design pattern
Organizing data into raw, processed, and curated zones with clear folders supports both goals effectively.Final Answer:
Organize data into raw, processed, and curated zones with clear folder structures -> Option DQuick Check:
Zones + clear folders = fast analytics + governance = C [OK]
- Storing all data together causing confusion
- Processing data only on-demand slowing queries
- Using unclear folder names causing management issues
Ready to prove it?
Pass the test and this pattern moves unknown
