Lambda architecture (batch + streaming) in Hadoop - Time & Space Complexity
We want to understand how the time needed to process data grows in a Lambda architecture using Hadoop.
Specifically, how batch and streaming parts affect the total work as data size increases.
Analyze the time complexity of the following Hadoop code snippet for batch and streaming layers.
// Batch layer: process large data in Hadoop MapReduce
job.setMapperClass(BatchMapper.class);
job.setReducerClass(BatchReducer.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
// Speed layer: process streaming data with small batches
StreamingJob streamingJob = new StreamingJob();
streamingJob.setMapperClass(StreamMapper.class);
streamingJob.setReducerClass(StreamReducer.class);
streamingJob.run();
This code runs two parts: batch jobs on big data sets and streaming jobs on small, fast data chunks.
Look at the loops and repeated processing steps.
- Primary operation: Batch layer runs MapReduce over all data once per batch.
- How many times: Batch runs periodically on full data; streaming runs continuously on small data chunks.
Batch layer time grows with total data size, streaming layer time grows with incoming data rate.
| Input Size (n) | Approx. Batch Operations | Approx. Streaming Operations |
|---|---|---|
| 10 GB | 10 units | 1 unit per small chunk |
| 100 GB | 100 units | 1 unit per small chunk |
| 1000 GB | 1000 units | 1 unit per small chunk |
Batch work grows linearly with total data size; streaming work depends on how fast data arrives, not total size.
Time Complexity: O(n)
This means the batch processing time grows linearly with the size of the data processed.
[X] Wrong: "Streaming layer time grows the same as batch because it processes all data."
[OK] Correct: Streaming processes small, recent data chunks continuously, not the entire dataset, so its time depends on data arrival rate, not total size.
Understanding how batch and streaming parts scale helps you explain real-world data processing systems clearly and confidently.
"What if the streaming layer started processing larger batches instead of small chunks? How would the time complexity change?"
Practice
Solution
Step 1: Understand batch layer role
The batch layer processes all accumulated data to provide accurate and comprehensive views.Step 2: Compare with other layers
The speed layer handles real-time data, not the batch layer.Final Answer:
To process all data for accurate and complete results -> Option AQuick Check:
Batch layer = accurate full data processing [OK]
- Confusing batch layer with speed layer
- Thinking batch layer processes data in real-time
- Assuming batch layer only stores raw data
Solution
Step 1: Identify real-time processing component
The speed layer is designed to process data streams in real-time for quick insights.Step 2: Eliminate other options
Batch layer processes full data, serving layer provides query results, storage layer is not a standard Lambda component.Final Answer:
Speed layer -> Option BQuick Check:
Speed layer = real-time data processing [OK]
- Choosing batch layer for real-time data
- Confusing serving layer with speed layer
- Thinking storage layer is a Lambda component
batch_result = batch_layer(data)
speed_result = speed_layer(stream)
final_result = merge(batch_result, speed_result)
print(final_result)
If batch_layer returns {'count': 100} and speed_layer returns {'count': 5}, what will final_result be after merging by summing counts?Solution
Step 1: Understand merging logic
Merging sums the 'count' values from batch and speed results: 100 + 5 = 105.Step 2: Confirm final result
The final dictionary after merging is {'count': 105}.Final Answer:
{'count': 105} -> Option AQuick Check:
100 + 5 = 105 [OK]
- Ignoring speed layer result
- Assuming merge replaces batch with speed
- Thinking merge causes error
def speed_layer(stream):
for record in stream:
process(record)
return processed_data
stream = get_stream()
result = speed_layer(stream)
print(result)
What is the likely error here?Solution
Step 1: Check variable initialization
The variableprocessed_datais returned but never defined or updated inside the function.Step 2: Verify other parts
Assumingstreamis iterable andprocess()exists, the main error is missingprocessed_datadefinition.Final Answer:
processed_data is not defined before return -> Option CQuick Check:
Undefined variable causes error [OK]
- Assuming process() is missing without checking
- Thinking stream is not iterable
- Ignoring variable initialization
Solution
Step 1: Understand serving layer role
The serving layer combines batch and speed layer outputs to provide accurate and timely results.Step 2: Evaluate options
Merge speed and batch results continuously, updating serving layer with combined data merges both results continuously, ensuring the serving layer is both up-to-date and accurate.Final Answer:
Merge speed and batch results continuously, updating serving layer with combined data -> Option DQuick Check:
Serving layer = combined batch + speed data [OK]
- Using only speed or batch layer results alone
- Replacing speed results abruptly without merging
- Ignoring serving layer's combining role
Ready to prove it?
Pass the test and this pattern moves unknown
