From Big Data to the Cloud, Part 2.1 — Inside Hadoop: HDFS and MapReduce

From Big Data to the Cloud, Part 2.1 — Inside Hadoop: HDFS and MapReduce

Leader ●7 ●30 ●72
calendar_today • schedule6 min read
— Originally published at husseinmahdi.xyz

A calm, sequential guide for anyone entering the field. The article is divided into smaller chapters to make it easier to understand.

Part 1 built the problem, and it built it carefully. Data has grown too large, too fast, and too varied for traditional tools. A single powerful machine breaks in five places, and every one of those breaking points reduces to three questions — storage, processing, and scalability. The way out was to stop making one machine bigger and use many ordinary machines together: a cluster. But the cluster came with a bill of its own. The moment data is spread across many machines, we must answer three new questions: which data lives on which node? How do the nodes communicate and coordinate? And what happens when a machine crashes — which, in a large cluster, is normal?

Part 1 ended by meeting Hadoop at a glance, as a name for each answer: HDFS for storage, MapReduce for processing, YARN for resource management, Hadoop Common for the shared plumbing. But a name is not an explanation. Part 2 opens each component and looks at it from the inside, across two articles. This one — Part 2.1 — takes the two components that touch the data directly. HDFS shows how a file is cut into pieces, spread across machines, and still never lost when a machine dies. MapReduce shows how that data is processed in parallel without being dragged across the network. Part 2.2 then takes the component that keeps everyone in order — YARN — and follows a single job through the cluster from submission to finish.

The questions from Part 1 do not change. What changes is that we now watch them being answered, one mechanism at a time.


Chapter 1: Hadoop as a Layered Stack

Four Components, Four Jobs

Before we open anything, it is worth fixing the map we will be reading from. Hadoop's core is made of four components, and each one has exactly one job.

Component Role Simple meaning
HDFS Storage Where the data lives
MapReduce Processing How the data is processed
YARN Resource management Who gets which CPU and memory
Hadoop Common Shared utilities Libraries all the others use

Why "Stack"

These four are not side by side; they sit on top of one another. HDFS is at the bottom, because everything else needs the data to be somewhere first. YARN sits above it, managing the cluster's CPU and memory. MapReduce sits on top, because a processing job needs both data to read and resources to run on. Hadoop Common runs alongside all three, since every layer relies on its shared libraries.

<!-- IMAGE 2 — LAYERED STACK File: big-data-2-1.1.webp Show: HDFS at the bottom, YARN in the middle, MapReduce on top, Hadoop Common running vertically beside all three. Source: Lab 2 ("Hadoop: A layered stack" slide). -->

We climb the stack in the order the problems arise. First the data must be stored — that is HDFS, the next chapter. Then it must be processed — that is MapReduce, the chapter after. The layer between them, YARN, which shares the cluster's resources between everyone who wants to process something, gets its own article in Part 2.2.


Chapter 2: HDFS — Where the Data Lives

Hadoop's Primary Storage

HDFS, the Hadoop Distributed File System, is Hadoop's primary storage system. It answers the first new question from Part 1 — which data lives on which node? — and it begins with a simple move: large files are split into blocks, and the blocks are spread across many machines.

Blocks

The default block size is 128 MB in Hadoop 2 and later (it was 64 MB in Hadoop 1). A file is cut into as many full 128 MB blocks as fit, and whatever is left over becomes one final, smaller block.

Take a 400 MB file. Three full blocks use up

\[ 3 \times 128\ \text{MB} = 384\ \text{MB}, \]

which leaves

\[ 400\ \text{MB} - 384\ \text{MB} = 16\ \text{MB} \]

for a fourth block. So the file becomes 4 blocks: A, B, and C of 128 MB each, and D of 16 MB.

It is worth being exact about why the blocks are so large, because it is a common source of confusion. Something has to remember where every block lives, and the fewer blocks there are, the less there is to remember. Large blocks mean less metadata to track. If the same 400 MB file were cut into tiny pieces, it would turn into a long list of entries to keep track of; at 128 MB, it is four.

<!-- IMAGE 3 — BLOCKS AND HEARTBEATS File: big-data-2-1.2.webp Show: the "Data Blocks in Hadoop HDFS" diagram — a 400 MB file split into A = 128 MB, B = 128 MB, C = 128 MB, D = 16 MB — next to a NameNode connected to three DataNodes, with one heartbeat line. Source: Lab 2, slide 7. Tip: the heartbeat label in the lab version reads "I'm live" — worth correcting to "I'm alive". -->

The Master and the Workers

Splitting a file into blocks creates the obvious next question: once block A is on one machine and block D is on another, who remembers that? HDFS answers with a master–slave design, and the two roles are kept strictly apart.

  • The NameNode (master) stores the metadata: file names, permissions, and which block is on which machine. It stores no actual data.
  • The DataNodes (slaves) store the actual data blocks and handle read and write requests.

The split is the whole idea. The NameNode is the cluster's index — it knows where everything is but holds none of it. The DataNodes are the shelves — they hold everything but need no knowledge of the bigger picture. This is the precise answer to Part 1's first question: which data lives on which node is a question you ask the NameNode.

The Heartbeat

The NameNode keeps a map of where every block lives, but a map is only useful if the places on it still exist. So every DataNode sends the NameNode a heartbeat every 3 seconds — a small message that says, in effect, "I'm alive."

This is how the cluster notices failure without anyone watching it. As long as the heartbeats arrive, the NameNode knows its DataNodes are healthy. When a DataNode's heartbeats stop, the NameNode knows that machine is gone — and, because it holds the map, it knows exactly which blocks were on it.

Replication

Knowing a machine is gone is only half the answer to Part 1's third question. The other half is not losing anything when it goes. HDFS's answer is replication: every block is stored more than once, on different nodes.

The default replication factor is 3 — the block plus two copies, each on a different machine. Return to our 400 MB file. It was 4 blocks, but with three copies of each, the cluster actually stores

\[ 4\ \text{blocks} \times 3\ \text{copies} = 12\ \text{blocks}. \]

Now the heartbeat and replication work together. If a DataNode fails, the data on it is not lost; it is simply read from another copy on another machine. That is fault tolerance, and it is exactly what Part 1 demanded of any system where failure is normal.

<!-- IMAGE 4 — A DATANODE FAILS File: big-data-2-1.3.webp Show: the NameNode with three DataNodes, where DataNodes-1 and DataNodes-2 send heartbeats (red lines) and DataNodes-3 is shown in red with no heartbeat line. Source: Lab 2, slide 9. Tip: same "I'm live" → "I'm alive" fix as the previous image. -->

a DataNode stops sending heartbeats - from-big-data-to-the-cloud

Fault tolerance is not free, and the same arithmetic shows its price. Part 1 listed it among Hadoop's limitations: replication uses extra storage space. Our 400 MB file occupies

\[ 400\ \text{MB} \times 3 = 1{,}200\ \text{MB} \]

of raw disk across the cluster. HDFS pays for safety in disks.

What If the NameNode Fails?

Replication protects the DataNodes. But look again at the design: there are many DataNodes, and only one NameNode — and it holds the only map of where everything lives. That makes the NameNode a single point of failure. If it goes down, the whole cluster is inaccessible: the blocks are all still sitting safely on the DataNodes, but nobody knows which block is where.

Two mechanisms address this, and it is worth keeping them apart, because their names invite confusion.

The Secondary NameNode periodically saves a checkpoint of the NameNode's metadata, which helps recovery. Despite its name, it is not a live backup that takes over automatically. If the NameNode fails, the Secondary NameNode does not step in; it simply holds a recent copy of the map to recover from.

High Availability (HA) is the setup that actually keeps the cluster running. It pairs an Active NameNode with a Standby NameNode. If the active one fails, the standby takes over, and the cluster keeps running.

A note on the two names. The word "secondary" makes it tempting to read the Secondary NameNode as a spare that waits to replace the master. It is not. Read it as a helper that takes snapshots of the map. The node that genuinely replaces a failed NameNode is the Standby in an HA setup. Checkpoint helper versus live replacement — that is the whole distinction.

<!-- IMAGE 5 — HDFS ARCHITECTURE File: big-data-2-1.4.webp Show: HDFS Client → Name Node ↔ Secondary Name Node, with dashed arrows from the Name Node down to five Data Nodes, each attached to its own disk. Source: Lab 2, slide 11. -->

HDFS at a Glance

Question HDFS's answer
Which data lives on which node? The NameNode keeps the map of which block is on which machine
How do we notice a machine has failed? DataNodes send a heartbeat every 3 seconds; silence means failure
How do we avoid losing data when it does? Every block is replicated 3 times on different nodes
What if the map itself is lost? Secondary NameNode checkpoints; HA adds a Standby that takes over

The data now lives safely on many machines. The next question is how to use it.


To read the full article, click the following link to the original article :

https://husseinmahdi.xyz/writing/big-data-2-1/


References
Deshpande, T., Karanth, S., & Turkington, G. Hadoop: Data Processing and Modelling (Learning Path). Packt Publishing.
Oracle. What Is Big Data? https://www.oracle.com/big-data/what-is-big-data/
Big Data — Understanding Hadoop: Architecture, Features, Challenges & Applications. Medium. https://medium.com/@rp99452/big-data-understanding-hadoop-architecturefeatures-challenges-applications-c7ab7011e375
Mehta, C. B. (2022). A Comprehensive Review of Hadoop Ecosystem for Big Data Processing and Analytics. IJNRD, 7(10).

Want more #programming & #programming deep dives?

Join 6,024+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

1 Comment

0 votes

More Posts

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelski - Mar 19

A Message From Our Founder: On the Winding Down of LaaSy™

Ken W. Algerverified - Oct 29

TypeScript Complexity Has Finally Reached the Point of Total Absurdity

Karol Modelski - Apr 23

Why “Building in Public” Is Hollowing Out Your Developer Career

Karol Modelski - Jun 18

Frameworks Are Institutional Memory

Ken W. Algerverified - Sep 17
chevron_left
5.1k Points • 109 Badges
19Posts
76Comments
14Connections
Research Engineer at @Era-Vision.| .NET | Java | Efficient Deep Learning | Complex & Higher-Order Networks | https://husseinmahdi.xyz

Related Jobs

View all jobs →

Commenters (This Week)

8 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!