Riya's problem list, ticked off one by one
On the whiteboard, Riya has written every problem BharatSearch hit while growing: doesn't fit, disks die, too slow, network jammed, too much plumbing code, adding machines is painful, costs too much. Arjun Sir hands her a green marker. “For each one, write the part of Hadoop that fixes it. If you can fill this board, you understand Hadoop's architecture.”
“Doesn't fit”: HDFS cuts files into blocks and spreads them over many machines.
Good. And “disks die”?
Three copies of every block, on different racks. And the NameNode re-copies when a node dies.
“Too slow” is MapReduce: thousands of small tasks running at the same time. “Network jammed” is data locality.
And the one most people forget?
“Too much plumbing.” We only write map and reduce, and Hadoop does the splitting, scheduling, retrying and merging.
Then I'll add two harder lines to your board: “the master is a single point of failure” and “only one kind of job can run”. Hadoop 1 couldn't fix those. Hadoop 2 did, with High Availability and YARN. Today we'll go through every line, see each fix in action, and then be honest about the problems Hadoop didn't solve.
Hadoop's architecture as a set of answers
Apache Hadoop consists of four core modules. Hadoop Common: shared libraries and utilities. HDFS: a distributed file system that splits files into large blocks, replicates each block across DataNodes and racks, and keeps metadata on a NameNode, providing scalable, fault-tolerant, high-throughput storage. YARN (since Hadoop 2): a cluster resource manager that allocates CPU and memory as containers to many applications. MapReduce: a programming model and engine in which user-defined map and reduce functions are executed in parallel near the data, with the framework handling partitioning, scheduling, shuffling, sorting and failure recovery.
Hadoop is four pieces. HDFS stores huge files safely across many machines. MapReduce processes them in parallel. YARN decides which job gets which machines' CPU and memory. Common holds the shared code. Each piece was built to fix a specific problem of big data.
Words you'll meet in this lesson
Problem → solution map
| Data bigger than one machine | HDFS splits files into 128 MB blocks across many DataNodes |
|---|---|
| Cheap hardware fails | Replication (3, rack-aware), heartbeats, re-replication, checksums |
| Processing too slow | MapReduce: one map task per block, thousands in parallel |
| Network too slow to move data | Data locality: tasks scheduled on nodes holding the block |
| Distributed code is hard | Write map and reduce; the framework does splits, scheduling, shuffle, retries |
| Tasks fail mid-job | Automatic re-execution (up to 4 attempts) and speculative execution |
| Need to grow | Add nodes; the NameNode tracks every block, the balancer spreads data |
| Raw, messy data | HDFS stores any bytes: schema-on-read |
| Master is a single point of failure | NameNode HA (Hadoop 2+), multiple standbys (Hadoop 3) |
| Only MapReduce could run | YARN (Hadoop 2+): Spark, Tez, Hive and others share one cluster |
| 3× storage is expensive | Erasure coding (Hadoop 3): about 1.5× for cold data |
The architecture at three levels
Beginner A courier company
- HDFS is the warehouse network: parcels (blocks) stored in many warehouses (nodes), each parcel copied to three warehouses in different areas.
- The NameNode is the head office register: it knows which warehouse holds which parcel, but never touches the parcels.
- MapReduce is the sorting work: every warehouse sorts its own parcels by city at the same time (map), then all parcels for one city go to one hub (shuffle) to be counted (reduce).
- YARN is the staff manager: it decides which team uses which warehouse workers today.
Intermediate How the pieces work together on one job
- You copy a file into HDFS: the NameNode picks DataNodes, the client writes blocks to them in a pipeline.
- You submit a job: YARN starts an ApplicationMaster for it.
- The ApplicationMaster asks the NameNode where the input blocks are, then asks YARN for containers on those nodes.
- Map tasks read their local blocks; outputs are shuffled to reducers; reducers write results back to HDFS.
- Throughout, heartbeats let the masters notice failures and re-run work.
Advanced What Hadoop did not solve (and what came next)
- Latency: MapReduce jobs take seconds to start and write intermediate data to disk. Interactive SQL came from Impala, Presto/Trino, Hive LLAP and cloud warehouses.
- Iterative algorithms (machine learning, graph processing) reread data in every pass. Spark keeps working data in memory and became the main engine.
- Streaming: MapReduce is batch-only. Kafka, Flink and Spark Structured Streaming handle real-time data.
- Small files: every file and block costs NameNode memory. Mitigations: bigger files, HAR/SequenceFiles, compaction, federation.
- Updates: HDFS files are write-once. Table formats like Apache Iceberg, Delta Lake and Hudi added updates and deletes on top of files.
- Operations and security: running Kerberos, Ranger, upgrades and capacity planning takes skilled staff. Managed cloud services reduced this burden.
Exam tip: For “Explain the core components of Hadoop”, name all four (Common, HDFS, YARN, MapReduce), give each one's job in one line, and connect each to the problem it solves. Adding one line on Hadoop's limitations (latency, small files, iterative jobs) shows real understanding.
The four core modules, side by side
Hadoop Common
Configuration system (core-site.xml), file-system abstraction, RPC, security, command-line tools. Everything else is built on it.
HDFS
NameNode (metadata), DataNodes (blocks), optional standby NameNode and JournalNodes for HA. Commands: hdfs dfs ….
YARN
ResourceManager (cluster-wide scheduler), NodeManagers (run containers), one ApplicationMaster per job.
ResourcesMapReduce
Java API (Mapper, Reducer, Job) and the engine that runs map, shuffle, sort and reduce as a YARN application.
Hadoop's strengths and limits
| Hadoop is good at | Hadoop is weak at |
|---|---|
| Storing petabytes cheaply and safely | Millisecond lookups of single records |
| Scanning whole data sets in parallel | Interactive queries with MapReduce (start-up cost) |
| Surviving hardware failures automatically | Many small files |
| Raw and semi-structured data (logs, JSON, text) | Updating records in place |
| Long-running batch pipelines | Real-time streams and iterative ML (without Spark etc.) |
When someone asks “Can Hadoop do X?”, ask yourself which problem on Riya's board X belongs to. If X is about large, batch, throughput, Hadoop fits. If X is about small, instant, constantly changing, another tool is usually better, even if it stores its history in HDFS.
A word count, and which Hadoop part handles each step
Store: put the file in HDFS
HDFS splits the file into 128 MB blocks and writes 3 replicas of each to DataNodes on two racks. Solves: doesn't fit and disks die.hdfs dfs -put pages.txt /data/pages.txtMap: each task reads one block
Your only code. MapReduce runs one copy per block, in parallel, on nodes that hold the blocks (locality). Solves: too slow and network jammed.def map_words(line): return [(w, 1) for w in line.lower().split()] print(map_words("Pune Delhi Pune"))[('pune', 1), ('delhi', 1), ('pune', 1)]Shuffle and sort: group by key
Done entirely by the framework: map outputs are partitioned by key, copied over the network to reducers and sorted. Solves: too much plumbing.pairs = [("pune", 1), ("delhi", 1), ("pune", 1)] groups = {} for k, v in sorted(pairs): groups.setdefault(k, []).append(v) print(groups){'delhi': [1], 'pune': [1, 1]}Reduce: combine each key's values
Your second function. Reducers write results back to HDFS, replicated like any other file.def reduce_count(word, ones): return word, sum(ones) print(reduce_count("pune", [1, 1]))('pune', 2)Recover: a node dies halfway
A DataNode with three running map tasks loses power.
YARN and the ApplicationMaster re-run those tasks on other nodes, reading other replicas. The job finishes. Solves: tasks fail mid-job.
Six problems, six fixes: the board and the cluster
Each frame takes one line from Riya's board. Left: the problem as a user feels it. Right: the Hadoop mechanism that fixes it.
- Storage: 400 TB of data and disks of 4 TB. No single machine can hold it.
- Reliability: with one copy, a dead disk means lost data and a failed job.
- Speed: one machine reading 400 TB takes days.
- Network: pulling all the data to a central place saturates the network.
- Complexity: distribution code dwarfs the actual business logic.
- Growth: adding machines forces a painful manual re-shard.
- HDFS cuts the file into blocks and spreads them, so capacity is the sum of every node's disks.
- Replication: each block lives on three nodes; when one dies, the NameNode makes a new copy from the others.
- MapReduce runs one task per block, all at the same time, so reading 400 TB takes minutes, not days.
- Locality: tasks run where their blocks are, so input data doesn't cross the network.
- The programming model: you write two small functions; Hadoop handles everything around them.
- Growth: a new DataNode registers and starts receiving blocks. The NameNode tracks blocks individually, so no re-sharding.
Try it yourself: test every fix
This cluster has everything switched on, including High Availability for the NameNode. Work through the checklist to see each fix with your own eyes.
Which fix matters most, by industry
1. Telecom: cheap, safe storage for years
Regulations require keeping call and data records for years. HDFS on commodity disks with replication (or erasure coding for old data) is far cheaper per TB than enterprise storage.
2. Banking: finishing the batch window
End-of-day risk and reconciliation jobs must finish before morning. Parallel processing near the data and automatic retries make the deadline reliable, even when nodes fail at night.
3. E-commerce: schema-on-read for app events
App events change format every few weeks as new features ship. Storing them raw in HDFS and applying a schema at query time (Hive, Spark) means nothing is lost when the format changes.
4. Many teams, one cluster
With YARN, the fraud team's Spark jobs, the BI team's Hive queries and nightly MapReduce jobs share one cluster, each in its own queue with guaranteed capacity (Module 11).
5. Always-on data platforms
When dashboards and pipelines depend on HDFS around the clock, NameNode High Availability turns a master failure from an outage into a short pause.
Examples are simplified descriptions of common patterns.
A tiny MapReduce, in 20 lines of Python
This is the whole MapReduce idea on one machine. map_fn and reduce_fn are the only parts you would write in Hadoop; run_job plays the framework: it splits the input, runs every map, shuffles and sorts by key, and runs every reduce.
def map_fn(line): # YOU write this
city, amount = line.split(",")
return [(city, int(amount))]
def reduce_fn(city, amounts): # YOU write this
return city, sum(amounts)
def run_job(lines, splits=2): # HADOOP does this part
parts = [lines[i::splits] for i in range(splits)]
mapped = [kv for part in parts for line in part for kv in map_fn(line)]
groups = {}
for k, v in sorted(mapped): # shuffle and sort by key
groups.setdefault(k, []).append(v)
return [reduce_fn(k, vs) for k, vs in groups.items()]
orders = ["Pune,240", "Delhi,120", "Pune,60", "Goa,300", "Delhi,80"]
print(run_job(orders))def map_fn(line):Map: turn one input record into zero or more (key, value) pairs. Here: (city, amount).parts = [lines[i::splits] for i in range(splits)]Split the input into pieces, like HDFS blocks.lines[i::2]takes every second line starting ati.for k, v in sorted(mapped):Shuffle and sort: all values with the same key end up together, in key order.return [reduce_fn(k, vs) for k, vs in groups.items()]Reduce: called once per key with the list of all its values.
Map, shuffle and reduce, one line at a time
Follow three orders through map (records → pairs), shuffle (pairs grouped by key) and reduce (one total per city). Watch the groups dictionary build up.
Worked examples: real problems, solved and traced in memory
Three problems that show each layer of Hadoop doing its job: a MapReduce on business data, the storage cost of replication versus erasure coding, and the gain from YARN sharing one cluster. Each runs live and is traced in memory.
Total sales per store with map and reduce
Problem statement
A chain of chai stalls logs each sale as store,item,amount. Using only a map function and a reduce function, compute the total sales per store.
["Kharghar,chai,20", "Vashi,samosa,15", "Kharghar,samosa,15", "Vashi,chai,20", "Kharghar,chai,20"]
('Kharghar', 55)
('Vashi', 35)Approach
- Map: from each line, emit (store, amount).
- Shuffle: group amounts by store (sorted).
- Reduce: sum each store's list.
Solution: run it live
What happens in memory, step by step
Recorded from a real Python run: press Next to execute one line at a time. Watch variables change in each frame, and lists and dictionaries (numbered #1, #2 …) fill up as objects.
Replication or erasure coding for old data?
Problem statement
A telecom keeps 600 TB of call records. The last 3 months (60 TB) are hot; the rest is cold. Compare raw disk needed if everything uses 3× replication, versus hot data at 3× and cold data with erasure coding (RS-6-3, 1.5×).
600 TB total · 60 TB hot · replication 3× · erasure coding 1.5×
All 3x replication: 1800 TB raw Hot 3x + cold EC : 990.0 TB raw Saving: 810 TB (45%)
Approach
- All replicated: 600 × 3.
- Mixed: 60 × 3 + 540 × 1.5.
- Print the saving.
Solution: run it live
What happens in memory, step by step
Recorded from a real Python run: press Next to execute one line at a time. Watch variables change in each frame, and lists and dictionaries (numbered #1, #2 …) fill up as objects.
Why sharing one cluster with YARN beats separate clusters
Problem statement
Three teams each have their own 20-node cluster. Their busy hours differ: each cluster is 90% busy for 6 hours a day and 10% busy for the rest. Compare average utilisation with separate clusters, and the number of nodes a shared YARN cluster would need to give every team its peak.
3 teams × 20 nodes · 90% busy 6 h, 10% busy 18 h · peaks at different times
Separate clusters: 30% average utilisation, 60 nodes Shared YARN cluster: about 22 nodes busy at worst With 25% spare: 28 nodes instead of 60
Approach
- Average utilisation of one cluster = (0.9 × 6 + 0.1 × 18) ÷ 24.
- Shared cluster: at any hour, at most one team is at peak (18 nodes busy) and two are quiet (2 each).
- Nodes needed = 18 + 2 + 2, plus some spare.
Solution: run it live
What happens in memory, step by step
Recorded from a real Python run: press Next to execute one line at a time. Watch variables change in each frame, and lists and dictionaries (numbered #1, #2 …) fill up as objects.
Check yourself
Quick revision
Lesson 2.3 in one screen
- Four core modules: Common (shared code), HDFS (storage), YARN (resources), MapReduce (processing).
- Doesn't fit → HDFS blocks. Disks die → 3 replicas, re-replication, checksums.
- Too slow → parallel map tasks. Network → data locality.
- Plumbing → you write map + reduce; framework does splits, scheduling, shuffle and sort, retries.
- Growth → add nodes; NameNode tracks each block; balancer spreads data.
- Hadoop 2: YARN (many engines, better scale) + NameNode HA. Hadoop 3: erasure coding, multiple standbys.
- Schema-on-read: store raw, structure at query time.
- Not solved by MapReduce: low latency, iterative ML, streaming, small files, in-place updates → Spark, Flink, Trino, Iceberg/Delta/Hudi.
Interview and viva questions
What are the core components of Hadoop?
Hadoop Common (shared libraries, configuration and utilities), HDFS (distributed storage with a NameNode for metadata and DataNodes for blocks), YARN (resource management with a ResourceManager, NodeManagers and per-application ApplicationMasters) and MapReduce (the batch processing model and engine that runs on YARN).
How does Hadoop achieve scalability?
By scaling out: HDFS spreads blocks over any number of DataNodes and the NameNode tracks each block individually, so adding nodes adds capacity without re-sharding. MapReduce creates one task per input split, so more nodes means more tasks run in parallel. YARN schedules resources across all nodes.
Which part of a MapReduce job is handled by the framework?
Computing input splits, scheduling map tasks near their data, running the map tasks, partitioning, spilling, sorting and shuffling map outputs to reducers, merging them, running reduce tasks, writing output to HDFS, tracking progress and counters, and retrying failed or slow tasks. The developer supplies the map and reduce functions and job configuration.
What problems does Hadoop not solve well?
Low-latency queries and point lookups, iterative and interactive workloads with MapReduce, real-time streaming, very large numbers of small files, and in-place updates of records. Other tools fill these gaps: HBase for lookups, Spark for iterative and in-memory work, Flink/Kafka for streaming, Trino/Impala for interactive SQL, and table formats such as Iceberg, Delta Lake and Hudi for updates.
Why was YARN introduced?
In Hadoop 1 the JobTracker handled both resource management and job tracking, which limited cluster size and allowed only MapReduce jobs. YARN separated these: the ResourceManager manages resources for the whole cluster, and each application has its own ApplicationMaster. This improved scalability and let other engines like Spark and Tez share the same cluster.
Practice problems
Practise the MapReduce way of thinking (map → shuffle → reduce) and the arithmetic behind Hadoop's storage choices.
Map one line
Write a map function that turns "Pune,UPI,450" into ("UPI", 450), and test it.
"Pune,UPI,450"
('UPI', 450)Show solution and explanation
def map_fn(line):
city, mode, amount = line.split(",")
return (mode, int(amount))
print(map_fn("Pune,UPI,450"))How it works: The key you emit decides how data is grouped. Here the key is the payment mode.
Group pairs by key
Group these pairs by key into a dictionary of lists: [("a",1),("b",2),("a",3)].
[("a",1),("b",2),("a",3)]{'a': [1, 3], 'b': [2]}Show solution and explanation
pairs = [("a", 1), ("b", 2), ("a", 3)]
groups = {}
for k, v in pairs:
groups.setdefault(k, []).append(v)
print(groups)How it works: This is the shuffle in one loop. In Hadoop it happens across the network between thousands of tasks.
Raw disk for replication 3
How much raw disk does 250 TB of data need with replication 3, and with erasure coding at 1.5×?
250 TB
Replication: 750 TB | EC: 375.0 TB
Show solution and explanation
print("Replication:", 250 * 3, "TB | EC:", 250 * 1.5, "TB")How it works: 750 TB vs 375 TB. EC halves raw storage for data that is rarely read.
Average order per city
Using map and reduce, compute the average order amount per city.
["Pune,240", "Delhi,120", "Pune,60", "Delhi,80", "Goa,300"]
Delhi 100.0 Goa 300.0 Pune 150.0
Show solution and explanation
orders = ["Pune,240", "Delhi,120", "Pune,60", "Delhi,80", "Goa,300"]
groups = {}
for city, amt in sorted((o.split(",")[0], int(o.split(",")[1])) for o in orders):
groups.setdefault(city, []).append(amt)
for city, amts in groups.items():
print(city, sum(amts) / len(amts))How it works: Average must be computed in the reducer from all values. Averaging partial averages from different mappers would give wrong answers.
Count words longer than 4 letters
Write map and reduce logic that counts only words longer than 4 letters.
["Hadoop stores data", "Spark caches data in memory"]
{'caches': 1, 'hadoop': 1, 'memory': 1, 'spark': 1, 'stores': 1}Show solution and explanation
lines = ["Hadoop stores data", "Spark caches data in memory"]
pairs = [(w.lower(), 1) for l in lines for w in l.split() if len(w) > 4]
counts = {}
for w, one in sorted(pairs):
counts[w] = counts.get(w, 0) + one
print(counts)How it works: Filtering in the map step means fewer pairs are shuffled. Doing work early, before the network, is a key MapReduce habit.
Which tool for the job?
For each workload, print whether batch Hadoop fits ("yes") or not ("no").
scan 2 years of logs · show one user profile in 50 ms · nightly sales report · live fraud alert in 1 s
scan 2 years of logs : yes show one user profile in 50 ms : no nightly sales report : yes live fraud alert in 1 s : no
Show solution and explanation
workloads = {"scan 2 years of logs": "batch", "show one user profile in 50 ms": "lookup",
"nightly sales report": "batch", "live fraud alert in 1 s": "stream"}
for w, kind in workloads.items():
print(f"{w:32}: {'yes' if kind == 'batch' else 'no'}")How it works: Batch fits Hadoop. Lookups need a database or HBase; streams need Kafka with Flink or Spark Streaming.
NameNode memory for small files
A team stores 40 crore small files of 200 KB each (one block per file). Using about 150 bytes per file object and 150 per block object, estimate the NameNode memory. Then estimate it if the same data were packed into 256 MB files.
40 crore files × 200 KB · 150 B per object
Small files : ~112 GB of NameNode heap Packed files: ~0.09 GB
Show solution and explanation
files = 40_00_00_000
small_gb = files * 2 * 150 / 1024**3
data_mb = files * 200 / 1024
big_files = data_mb / 256
big_gb = big_files * 2 * 150 / 1024**3
print(f"Small files : ~{small_gb:.0f} GB of NameNode heap")
print(f"Packed files: ~{big_gb:.2f} GB")How it works: About 112 GB versus well under 1 GB for the same bytes. The small-files problem is one of the main things Hadoop did not solve by itself (Module 7).
Cost of keeping cold data replicated
Cold data of 900 TB is kept at 3× replication. Switching it to erasure coding (1.5×) frees raw disk. At Rs 2,500 per TB of raw disk, how much hardware does the switch save?
900 TB · 3× → 1.5× · Rs 2,500/TB
Saved 1350 TB raw = Rs 33.8 lakh
Show solution and explanation
saved_tb = 900 * (3 - 1.5)
print(f"Saved {saved_tb:.0f} TB raw = Rs {saved_tb * 2500 / 1e5:.1f} lakh")How it works: 1,350 TB of raw disk, about Rs 33.8 lakh of hardware (illustrative price), plus the power and rack space for it.
Real-world scenario questions (asked in company interviews)
Interviewers often test architecture knowledge by giving you a problem and asking which part of Hadoop handles it.
“Walk me through what happens when I run a Hadoop job.”
The interviewer wants the end-to-end flow, naming which component does what, for a job that reads a file in HDFS and writes results.
The interviewer is checking: can you connect HDFS, YARN and MapReduce into one story?
Show a strong answer
- The file is already in HDFS: blocks on DataNodes, metadata on the NameNode.
- The client submits the job to the ResourceManager, which starts an ApplicationMaster in a container.
- The AM computes input splits from block locations and asks YARN for containers on (or near) those nodes.
- NodeManagers launch map tasks; each reads its block locally and writes partitioned, sorted output to local disk.
- Reducers shuffle (fetch) their partitions from all mappers, merge them and run reduce, writing output to HDFS.
- The AM tracks progress and re-runs failed tasks; when done, it reports success and exits.
Avoid: mentioning the JobTracker for a modern cluster (that was Hadoop 1).
The ML training job takes 14 hours in MapReduce
A data scientist implemented a training algorithm with 30 iterations as 30 chained MapReduce jobs over the same 2 TB data set. It takes 14 hours.
The interviewer is checking: do you know which problems MapReduce did not solve, and what replaced it?
Show a strong answer
- Each MapReduce job rereads the 2 TB from HDFS and writes its results back to HDFS, so 30 iterations mean about 60 full passes over disk, plus job start-up each time.
- Move it to Spark on the same YARN cluster: load the data once,
cache()it in executor memory, and iterate in memory. Spark MLlib already has many algorithms. - Keep HDFS as the storage; only the engine changes.
Avoid: “Add more nodes.” The waste is in the repeated I/O, not the lack of machines.
Each team wants its own cluster
Three departments each ask for a separate 30-node Hadoop cluster so that “others don't slow us down”. Finance asks whether that is necessary.
The interviewer is checking: do you understand what YARN was built for?
Show a strong answer
- Separate clusters sit idle outside each team's busy hours, and data must be copied between them.
- One shared cluster with YARN queues (Capacity or Fair Scheduler) gives each team a guaranteed share, lets them borrow idle capacity, and keeps one copy of shared data.
- Isolation concerns are handled with queue limits, pre-emption, and per-team security (Kerberos, Ranger policies).
- Separate clusters can still make sense for strict regulatory isolation or very different software versions.
Avoid: dismissing the teams' concern; explain how queues address it.
“Just update the wrong rows in HDFS”
A bug wrote wrong interest amounts into 5,000 rows of a 2 TB table stored as files in HDFS. A manager asks you to “run an UPDATE on those rows”.
The interviewer is checking: do you know HDFS is write-once, and how updates are handled in practice?
Show a strong answer
- HDFS files can't be edited in the middle. Plain Hive tables on files are corrected by rewriting the affected partitions (for example only the dates involved).
- Modern table formats (Apache Iceberg, Delta Lake, Hudi) or Hive ACID tables support
UPDATE/MERGEby writing new files and tracking which rows are current. - Fix the bug first, then reprocess from raw data if possible, keeping the raw layer unchanged.
Avoid: suggesting editing HDFS blocks directly.