This page requires JavaScript to display.
H
Unpacking...
← Data Engineering
Data Engineering

Hadoop & HDFS Reference

Big data fundamentals, the Hadoop Distributed File System, the HDFS CLI, and Hive query tuning.

Contents
1. What is Big Data 2. Apache Hadoop 3. HDFS Architecture 4. Using the HDFS CLI 5. Command Reference 6. YARN Architecture 7. MapReduce Phases 8. HDFS Read/Write Path 9. Hadoop Ecosystem 10. Hive Query Tuning 11. Replication & Fault Tolerance 12. How Hive Reads Files 13. Hive's Problems & How They Were Solved

1. What is Big Data

Big data describes data whose volume, velocity and variety exceed what traditional databases and tools can capture, store and process. As internet, mobile and social usage grew, storing and managing that data became the central engineering challenge — not just analyzing it.

The 5 V's

VMeaning
VolumeThe sheer scale of data generated — from megabytes per user to daily consumption at cloud scale.
VelocityThe speed data arrives and must be processed — streaming clickstreams, transactions, sensor feeds.
VarietyStructured, semi-structured and unstructured data mixed together.
VeracityTrustworthiness and quality of the data.
ValueThe business insight that makes collecting it worthwhile.

Types of data

2. Apache Hadoop

Apache Hadoop (2006) is an open-source framework for distributed storage and processing of big data across clusters of commodity hardware. It assumes hardware failure is common and handles it automatically, making it highly scalable and fault tolerant. Hadoop splits files into large blocks, distributes them across cluster nodes, and processes them in parallel using a master–slave architecture.

HDFS
Distributed file system storing data on commodity hardware with high-speed aggregation across the cluster.
YARN
(2012) Manages and schedules computing resources across the cluster.
MapReduce
Programming model for large-scale parallel data processing.

3. HDFS Architecture

HDFS follows a master–slave design. The NameNode (master) holds filesystem metadata — the directory tree and which blocks live on which nodes — while DataNodes (slaves) store the actual block data and serve read/write requests. A Secondary NameNode periodically merges edit logs into the filesystem image; it is a checkpoint helper, not a hot standby.

Cluster node types
Gateway / client / edge nodes — where developers connect (via SSH) to interact with the cluster.
Master nodes — run NameNode, ResourceManager and similar coordination services.
Worker nodes — run DataNode and NodeManager, storing data and running tasks.

4. Using the HDFS CLI

As a developer you typically connect to a gateway/client node over SSH, then interact with HDFS using hadoop fs or hdfs dfs — the two are aliases of each other for filesystem operations. hadoop has other subcommands beyond fs and covers HDFS/MapReduce interaction broadly; hdfs has other subcommands beyond dfs and covers administrative tasks (NameNode, Secondary NameNode, DataNode). As developers, day-to-day scope is limited to hdfs dfs / hadoop fs.

Anatomy of a command, using hdfs dfs -ls -l -S -r /public as an example:

hdfs        → main command, manages all HDFS components
  dfs       → sub-command, manages files in HDFS
    -ls     → file system command: list files
      -l -S -r  → control arguments (long listing, sort by size, reverse)
        /public → argument: the HDFS path to list

5. Command Reference

CommandPurpose
hdfs dfs -help [cmd]Usage / help for a command
hdfs dfs -ls -R /pathList files, recursively
hdfs dfs -mkdir -p /pathCreate directory (and parents)
hdfs dfs -rm -r -skipTrash /pathDelete recursively, bypassing trash
hdfs dfs -put local.txt /pathCopy local → HDFS
hdfs dfs -get /path local.txtCopy HDFS → local
hdfs dfs -cp src dstCopy within HDFS
hdfs dfs -mv src dstMove / rename within HDFS
hdfs dfs -cat /pathPrint file contents
hdfs dfs -tail /pathPreview last kilobyte of a file
hdfs dfs -du -h /pathStorage used, human-readable
hdfs dfs -df -hFilesystem free/used capacity
hdfs dfs -stat "%b %r %n" /pathFile metadata: size, replication, name
hdfs dfs -setrep -w 2 /pathChange replication factor
hdfs dfs -chmod 750 /pathChange file permissions
hdfs dfs -chown user:group /pathChange file owner/group

6. YARN Architecture

YARN separates resource management from job scheduling/monitoring, letting Hadoop run more than just MapReduce on one cluster.

This is why Spark-on-YARN has a driver that runs as (or inside) the ApplicationMaster, and executors that run inside containers negotiated from the ResourceManager — the same YARN concepts underpin both classic MapReduce and modern Spark jobs.

7. MapReduce Phases

A MapReduce job processes data in four stages, each running in parallel across the cluster:

  1. Map — each mapper reads one input split and emits key-value pairs.
  2. Shuffle — the framework transfers each mapper's output to the reducer responsible for its key.
  3. Sort — keys arriving at a reducer are sorted, so a reducer sees all values for a key together and in order.
  4. Reduce — each reducer aggregates the values for its keys and writes final output, typically back to HDFS.

Shuffle is usually the most expensive phase — it moves data across the network — which is exactly why Spark's equivalent shuffle step is the first thing to tune (see §9 of the Spark reference doc).

8. HDFS Read/Write Path

Writing a file: the client asks the NameNode for a list of DataNodes to host the first block; it streams data to the first DataNode, which forwards it to the second, which forwards it to the third (a replication pipeline) — each DataNode acknowledges back up the pipeline once its copy is durable.

Reading a file: the client asks the NameNode for the block locations of a file; the NameNode returns DataNodes ordered by network proximity to the client, and the client reads each block directly from the nearest available replica — the NameNode itself never serves file data.

Safe mode — on startup, the NameNode enters safe mode: read-only, waiting for DataNodes to report in their block inventories before it considers the filesystem's replication state healthy enough to allow writes.

9. Hadoop Ecosystem

ToolRole
HiveSQL-on-Hadoop; translates HiveQL into MapReduce/Tez/Spark jobs over HDFS tables.
PigScripting language (Pig Latin) for data flows, compiled down to MapReduce.
SqoopBulk transfers between HDFS/Hive and relational databases.
OozieWorkflow scheduler that chains Hadoop jobs (Hive, Pig, MapReduce, Spark) together.
ZooKeeperDistributed coordination service — leader election and configuration for HDFS HA, HBase, Kafka and more.

10. Hive Query Tuning

Limit optimization

A bare LIMIT still runs the entire query before truncating results — wasteful for ad-hoc CLI exploration. Enable the optimizer so Hive samples input instead of scanning it all:

SET hive.limit.optimize.enable = true;
SET hive.limit.row.max.size = 100000;
SET hive.limit.optimize.limit.file = 10;

Trade-off: with sampling enabled, a query that also needs a full scan (a JOIN or GROUP BY) risks never seeing all the relevant input.

Join strategies

Ordering data

ClauseBehavior
ORDER BYTotal ordering — forces all data through one reducer. Slow at scale.
SORT BYOrders within each reducer only — output overlaps between reducers.
DISTRIBUTE BY colControls which reducer rows land on, pair with SORT BY.
CLUSTER BY colShorthand for DISTRIBUTE BY + SORT BY on the same column.

Other levers

11. Replication & Fault Tolerance

HDFS splits files into blocks (128 MB by default, often 256 MB) and stores each block on several DataNodes. The NameNode keeps only metadata in memory: the directory tree, file → blocks, and block → DataNodes.

Replication factor and rack awareness

The default replication factor is 3 (dfs.replication, or per path with hdfs dfs -setrep). Default placement: replica 1 on the writer's node, replica 2 on a node in a different rack, replica 3 on another node in that same remote rack. Losing any single node or any single rack loses no data, at the cost of 3× storage. Hadoop 3 erasure coding (e.g. RS-6-3) gives similar durability at about 1.5× storage, mainly for cold data.

How each failure is handled

FailureProtection
DataNodeNo heartbeat (every 3 s) for ~10.5 min → marked dead → its blocks are re-replicated from surviving copies
Corrupt blockCRC32C checksums verified on read and by a background scanner → read another replica, replace the bad copy
DiskDataNode keeps running with failed volumes tolerated; blocks re-replicated
RackRack-aware placement keeps a copy on another rack
NameNodeHA: Active + Standby, edits shared via JournalNodes, ZooKeeper failover controllers, fencing
TaskYARN reschedules it; Spark recomputes lost partitions from lineage
hdfs dfs -setrep -w 3 /data/txns                       # change replication, wait
hdfs dfs -stat "%o %r" /data/txns/part-0000            # block size, replication
hdfs fsck /data/txns -files -blocks -locations         # blocks and replica locations
hdfs dfsadmin -report                                  # live / dead DataNodes

12. How Hive Reads Files

Hive puts SQL on top of files. A table is just metadata in the Metastore (schema, location, format, partitions) laid over existing files: schema-on-read. Rows that do not fit the schema come back as NULLs instead of failing.

beeline / JDBC ──► HiveServer2 ──► Metastore (schema, location, format, partitions)
                       │
                       └──► Tez / Spark / MapReduce tasks ──► read HDFS blocks locally
CREATE EXTERNAL TABLE transactions (
  txn_id STRING, account_id STRING, channel STRING,
  amount DOUBLE, event_time TIMESTAMP)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
STORED AS TEXTFILE
LOCATION '/data/txns/'
TBLPROPERTIES ("skip.header.line.count"="1");

SELECT channel, COUNT(*), SUM(amount) FROM transactions GROUP BY channel;

Then vs now

On-prem HadoopCloud today
HDFSS3 / ADLS / GCS
YARNKubernetes, EMR, Databricks
MapReduce / Hive on MRSpark, Flink, Trino
Hive MetastoreStill used; Glue Catalog, Unity Catalog
Hive tablesDelta / Iceberg / Hudi

13. Hive's Problems & How They Were Solved

IssueRoot causeFixed inside HiveModern solution
Slow queries (minutes)MapReduce: JVM per job, HDFS writes between stages, row-at-a-timeTez, LLAP, vectorization, CBO (Calcite)Spark SQL, Trino, Snowflake, BigQuery
No UPDATE / DELETE / MERGEWrite-once files, no transaction logHive ACID (ORC delta files + compaction)Delta, Iceberg, Hudi
No isolationA table is just a directoryACID transactions and locksSnapshot isolation, optimistic concurrency
Small filesMicro-batches, many reducers, over-partitioninghive.merge.*, CONCATENATEDelta OPTIMIZE, Iceberg rewrite_data_files
Slow partition listing; partitions out of syncMetastore + directory listing (worst on S3)MSCK REPAIR, ADD PARTITIONFile lists in table metadata; Iceberg hidden partitioning
Silent NULLs from bad dataSchema-on-readSelf-describing formatsSchema enforcement; DQ tests (Great Expectations, Deequ, dbt)
Schema changes break readsPositional formats (CSV)Parquet/ORC match by nameIceberg column IDs; Delta column mapping
Slow joins, skewLarge shuffles, hot keysMap join, bucket map join, skew joinSpark AQE
No real-time or point lookupsBatch scan design—Kafka + Spark/Flink; HBase, Redis, MongoDB
Weak securityDirect file access bypasses HiveKerberos, Ranger/SentryUnity Catalog, Lake Formation
2010  Hive on MapReduce
2013  Stinger: Tez, ORC, vectorization
2016  Hive 2 + LLAP
2018  Hive 3: ACID by default
2019+ Lakehouse table formats queried by Spark / Trino
Today the Hive Metastore lives on as a catalog; the Hive engine is mostly legacy.