Hadoop Ecosystem
HDFS, MapReduce, and the Hadoop framework
The Foundation of Big Data Processing
Apache Hadoop is an open-source framework that revolutionized Big Data by enabling reliable and scalable distributed computing. Inspired by Google's GFS and MapReduce papers, it provides the core infrastructure for storing and processing massive datasets across clusters of commodity hardware. The ecosystem extends beyond core components to include tools for data ingestion, querying, workflow management, and more, forming a complete platform for Big Data applications.
In this lesson, we'll dive deep into the core: HDFS for storage, YARN for resource management, and MapReduce for processing. We'll also cover key ecosystem components that build upon these foundations.
1. HDFS: Hadoop Distributed File System
HDFS is a distributed file system designed for high-throughput access to large datasets. It stores data across multiple machines, providing fault tolerance through replication and enabling data locality for efficient processing.
Architecture Overview
HDFS follows a master-slave architecture:
Manages file system namespace, metadata, and block locations. Single point but with high-availability options.
Store actual data blocks (default 128MB each) and report to NameNode. Handle replication and data access.
Key Features
Default 3 copies for fault tolerance. Configurable per file.
Places replicas across racks to survive rack failures.
Optimized for streaming large files, not random writes.
Multiple NameNodes for scalability in large clusters.
Hands-On Examples (Shell Commands)
hdfs dfs -mkdir /user/data
hdfs dfs -Ddfs.replication=2 -put localfile.txt /user/data/file.txt
hdfs fsck /user/data/file.txt -files -blocks -locations
/user/data/file.txt 123456 bytes, 1 block(s): OK
0. BP-123:blk_1073741825_1001 len=123456 Live_repl=3 [DatanodeInfo1, DatanodeInfo2, DatanodeInfo3]
2. YARN: Yet Another Resource Negotiator
YARN is Hadoop's resource management layer, separating resource allocation from processing frameworks. It allows multiple engines (MapReduce, Spark) to run on the same cluster.
Architecture Overview
YARN uses a master-slave model for cluster resource management:
Global scheduler, allocates containers, handles applications.
Per-node agents, launch/monitor containers, report resources.
Per-app negotiator, requests resources, coordinates tasks.
Resource bundles (CPU, memory) for tasks.
Key Features
Multiple apps/engines share cluster securely.
Fair, Capacity, FIFO for resource allocation.
Active/Standby ResourceManagers.
Apps can request/release resources on-demand.
Hands-On Examples (Commands)
yarn node -list
Total Nodes:3
Node-Id: host1:8041 State:RUNNING
Node-Id: host2:8041 State:RUNNING
yarn jar hadoop-examples.jar pi 2 10
yarn logs -applicationId application_1234567890_0001
3. MapReduce: Distributed Processing Framework
MapReduce is a programming model for processing large datasets in parallel. It abstracts distributed execution into map (transform) and reduce (aggregate) functions.
Core Phases
Processes input key-value pairs, emits intermediate key-value pairs.
Groups and sorts intermediate data by key, sends to reducers.
Aggregates values for each key, emits final output.
Optional: Mini-reducers and custom partitioning for optimization.
Hands-On Examples (Java Code Snippets)
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
while (itr.hasMoreTokens()) {
context.write(new Text(itr.nextToken()), new IntWritable(1));
}
}Result (Emitted): (hello,1), (world,1)
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
context.write(key, new IntWritable(sum));
}Result (Emitted): (hello,3)
job.setMapperClass(WordCountMapper.class); job.setCombinerClass(WordCountReducer.class); // Mini-reducer for optimization job.setReducerClass(WordCountReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class);
Hands-On Examples (Python + mrjob)
def mapper(self, _, line):
for word in line.strip().split():
yield word.lower(), 1Emitted pairs: ("hello", 1), ("world", 1), ("hello", 1)
def reducer(self, word, counts):
yield word, sum(counts)Result (Emitted): ("hello", 3)
from mrjob.job import MRJob
class MRWordCount(MRJob):
def mapper(self, _, line):
for word in line.strip().split():
yield word.lower(), 1
def combiner(self, word, counts): # ← optimization!
yield word, sum(counts)
def reducer(self, word, counts):
yield word, sum(counts)
if __name__ == '__main__':
MRWordCount.run()python wordcount.py input.txt > output.txtOn Hadoop cluster:
python wordcount.py -r hadoop hdfs:///input/*.txt -o hdfs:///output/wordcountBenefit of combiner: Reduces network traffic by doing partial sums on each mapper node
4. Key Ecosystem Components
Hadoop's power comes from its rich ecosystem of integrated tools building on HDFS and YARN.
Data warehouse with SQL-like queries (HiveQL) on HDFS. Compiles to MapReduce/Spark jobs.
Scripting language (Pig Latin) for data flows. Good for ETL, compiles to MapReduce.
NoSQL database on HDFS. Column-oriented, for random read/write access.
Tool for transferring data between Hadoop and relational databases.
Service for collecting and aggregating streaming data (e.g., logs) into HDFS.
Workflow scheduler for managing Hadoop jobs (e.g., chain MapReduce, Hive).
Distributed coordination service for configuration, naming, synchronization.
Management tools for deployment, monitoring, and administration.
Key Takeaways
- HDFS provides scalable, fault-tolerant storage with replication and data locality.
- YARN manages resources efficiently, supporting multiple processing frameworks.
- MapReduce enables parallel processing via map-shuffle-reduce paradigm, ideal for batch jobs.
- The ecosystem extends Hadoop with tools for querying (Hive), NoSQL (HBase), ingestion (Sqoop/Flume), and orchestration (Oozie).
- Hadoop powers petabyte-scale systems but is often augmented with faster alternatives like Spark for modern workloads.
What's Next?
With Hadoop fundamentals in place, we're ready for faster processing! Next: Apache Spark for in-memory analytics.