Apache Hadoop
Apache Hadoop is an open-source framework for the distributed storage and distributed processing of very large datasets across clusters of commodity hardware. Created by Doug Cutting and Mike Cafarella in 2006 (named after Cutting's son's toy elephant), it was inspired by two Google papers — the Google File System (2003) and MapReduce (2004).
Core Design Principles
- Scale out, not up — add cheap commodity machines rather than buying bigger servers
- Assume failure is normal — with thousands of machines, something is always broken; handle it in software
- Move computation to the data — sending a small program to where data lives beats moving terabytes across the network (data locality)
- Write once, read many — optimised for large sequential reads, not random updates
- Hide distribution complexity — the programmer writes logic, the framework handles parallelism, scheduling, and recovery
The Four Core Modules
1. HDFS — Hadoop Distributed File System
HDFS stores very large files by splitting them into blocks distributed across the cluster, with each block replicated for fault tolerance.
HDFS Architecture Components
| Component | Role |
|---|---|
| NameNode (master) | Maintains the filesystem namespace and the block→DataNode map in memory. Does not store actual data. Single point of failure in Hadoop 1 (solved by HA NameNodes in Hadoop 2+). |
| DataNode (slave) | Stores actual data blocks; serves read/write requests; sends heartbeats (default every 3 s) and block reports to the NameNode. |
| Secondary NameNode | Not a backup and not a failover node. It periodically merges the NameNode's edit log into the fsimage checkpoint, preventing the edit log from growing unbounded. |
| Standby NameNode (HA) | The actual hot failover, introduced in Hadoop 2, coordinated via ZooKeeper and a shared journal. |
Blocks and Replication
Default block size: 128 MB (Hadoop 2+; 64 MB in Hadoop 1)
Default replication: 3
Example: a 500 MB file
Block 1: 128 MB
Block 2: 128 MB
Block 3: 128 MB
Block 4: 116 MB <- the last block uses only what it needs
Each of the 4 blocks is stored on 3 different DataNodes
-> 12 block replicas distributed across the cluster
-> actual disk consumed = 500 MB x 3 = 1.5 GB
Why such large blocks? To minimise the seek-time-to-transfer-time ratio. With 128 MB blocks, disk seek overhead becomes negligible relative to the sequential read, and the NameNode's metadata stays small.
Rack Awareness — The Default Replica Placement Policy
Replica 1: on the same node as the writer (or a random node if the client
is outside the cluster)
Replica 2: on a DIFFERENT RACK
Replica 3: on a different node in the SAME rack as replica 2
Why this policy:
• Surviving a whole-rack failure (replicas exist on ≥2 racks)
• Minimising cross-rack network traffic (only 1 cross-rack write)
• Balanced read load
HDFS Read and Write Flows
WRITE:
1. Client asks the NameNode to create the file
2. NameNode checks permissions and returns a list of DataNodes for block 1
3. Client writes to DataNode A, which PIPELINES to B, which pipelines to C
4. Acknowledgements flow back along the pipeline
5. Repeat for each block; client tells the NameNode the file is complete
READ:
1. Client asks the NameNode for the block locations of a file
2. NameNode returns DataNode addresses, sorted by network proximity
3. Client reads each block DIRECTLY from the nearest DataNode
(data never flows through the NameNode — it would be a bottleneck)
HDFS Characteristics
| Strength | Limitation |
|---|---|
| Handles very large files (GB to TB) | Poor with many small files — each consumes NameNode memory |
| High throughput for sequential reads | High latency — not for interactive/random access |
| Fault tolerant via replication | Write-once, append-only — no arbitrary in-place updates |
| Runs on cheap commodity hardware | Single NameNode is a bottleneck (mitigated by HDFS Federation) |
| Data locality reduces network load | Not a POSIX filesystem; not suitable for general-purpose storage |
Common HDFS Commands
hdfs dfs -ls /user/data # list a directory
hdfs dfs -mkdir /user/data/sales # create a directory
hdfs dfs -put local_file.csv /user/data/ # upload from local FS
hdfs dfs -get /user/data/output.csv ./ # download to local FS
hdfs dfs -cat /user/data/file.txt # print file contents
hdfs dfs -tail /user/data/file.txt # last KB of a file
hdfs dfs -rm -r /user/data/old # delete recursively
hdfs dfs -du -h /user/data # disk usage, human readable
hdfs dfs -setrep -w 2 /user/data/file.csv # change replication factor
hdfs dfsadmin -report # cluster health report
hdfs fsck / -files -blocks # filesystem check
2. YARN — Yet Another Resource Negotiator
Introduced in Hadoop 2, YARN separated resource management from the processing model, turning Hadoop from a MapReduce-only system into a general-purpose cluster operating system.
| Component | Role |
|---|---|
| ResourceManager | Global master; arbitrates cluster resources between all applications |
| NodeManager | Per-node agent; launches and monitors containers, reports resource usage |
| ApplicationMaster | One per application; negotiates containers from the RM and coordinates the application's tasks |
| Container | A bundle of resources (CPU, memory) on one node in which a task runs |
Schedulers: FIFO (simple, unfair), Capacity Scheduler (guaranteed queue capacities per organisation), and Fair Scheduler (all jobs get an equal share over time).
3. MapReduce
The original processing engine — covered in full in the next lesson.
The Hadoop Ecosystem
Ecosystem Component Reference
| Component | Category | Purpose |
|---|---|---|
| HDFS | Storage | Distributed file system |
| YARN | Resource management | Cluster resource scheduling |
| MapReduce | Processing | Batch programming model |
| Hive | Query | SQL-like queries (HiveQL) on HDFS data; compiles to MapReduce/Tez/Spark |
| Pig | Scripting | Dataflow language (Pig Latin) for ETL pipelines |
| HBase | NoSQL | Column-oriented store for random real-time read/write on HDFS |
| Sqoop | Ingestion | Bulk transfer between HDFS and relational databases ("SQL to Hadoop") |
| Flume | Ingestion | Streaming log and event data collection |
| Kafka | Streaming | Distributed publish-subscribe message log |
| Oozie | Workflow | Schedules and chains Hadoop jobs into DAGs |
| ZooKeeper | Coordination | Distributed configuration, naming, synchronisation, leader election |
| Mahout | ML | Scalable machine learning library |
| Spark | Processing | In-memory engine — batch, streaming, SQL, ML, graph |
| Ambari | Management | Web UI for provisioning, monitoring and managing a cluster |
| Impala / Presto | Query | Low-latency interactive SQL (MPP, bypasses MapReduce) |
| Avro / Parquet / ORC | Formats | Serialization and columnar storage formats |
Hive vs Pig vs HBase
| Basis | Hive | Pig | HBase |
|---|---|---|---|
| Language | HiveQL (SQL-like) | Pig Latin (dataflow) | Java API / shell |
| Paradigm | Declarative | Procedural | Key-value operations |
| Best for | Analysts who know SQL; reporting | Complex multi-step ETL | Random real-time read/write |
| Schema | Schema-on-read, structured | Handles semi/unstructured well | Column families, sparse |
| Latency | High (batch) | High (batch) | Low (real-time) |
| Data volume | Very large, batch | Very large, batch | Very large, random access |
Hadoop 1 vs Hadoop 2 vs Hadoop 3
| Feature | Hadoop 1 | Hadoop 2 | Hadoop 3 |
|---|---|---|---|
| Resource management | JobTracker/TaskTracker | YARN | YARN with improvements |
| Processing models | MapReduce only | Any (Spark, Tez, etc.) | Any |
| NameNode HA | ✗ (single point of failure) | ✓ Active/Standby | ✓ Multiple standbys |
| Max nodes | ~4,000 | ~10,000 | 10,000+ |
| Default block size | 64 MB | 128 MB | 128 MB |
| Storage efficiency | 3× replication | 3× replication | Erasure coding — ~1.5× overhead instead of 3× |
| Java version | Java 6/7 | Java 7 | Java 8+ |
Advantages and Limitations of Hadoop
| Advantages | Limitations |
|---|---|
| Scalable — add nodes horizontally, near-linear | High latency — batch only, not for interactive queries |
| Cost-effective — commodity hardware, open source | Small-file problem — NameNode memory pressure |
| Fault tolerant — automatic replication and task re-execution | Steep learning curve; complex cluster administration |
| Flexible — schema-on-read handles any data type | No in-place updates — write-once model |
| Data locality — computation moves to the data | MapReduce is verbose and disk-bound (Spark solves this) |
| Mature ecosystem with broad tool support | Weaker built-in security than enterprise RDBMS (Kerberos needed) |
| High throughput on massive sequential scans | Not suited to real-time or transactional (OLTP) workloads |
The next lesson explains the programming model at Hadoop's heart: MapReduce.