Hadoop Distributed File System (HDFS) Explained: Blocks, Replication and a 300 MiB Worked Example

Follow one 300 MiB HDFS file from NameNode metadata to DataNode blocks, nine replicas and failure recovery, with exam traps explained along the way.

KnowledgeGate Team

Exam prep & CS education

Updated 27 Nov 20266 min read
Hadoop Distributed File System (HDFS) Explained: Blocks, Replication and a 300 MiB Worked Example

HDFS is often reduced to "NameNode plus DataNodes", but exam questions mix four separate ideas: who stores metadata, how a file becomes blocks, where replicas go, and what survives a node failure. /exam/results.csv is a 300 MiB file with a 128 MiB block size and replication factor 3. These numbers are teaching assumptions because HDFS settings are configurable. Follow this one path through the calculation, placement and recovery trace, then use CS Fundamentals for Exams & Placements to place HDFS within the wider systems syllabus.

What HDFS is designed to do, and what it is not designed to do

The Apache HDFS Architecture guide describes reliable storage on commodity hardware, automatic recovery, streaming access to large data sets and high throughput. Its model is write-once-read-many, with append and truncate support.

HDFS suits large sequential reads and batch processing, not low-latency interactive access or huge populations of tiny files. Each file adds metadata that the NameNode must hold even when its payload is small. HDFS sits under Big Data Systems in DBMS, so the DBMS subject map is a useful next step. Unlike a local file system on one machine, HDFS presents a namespace across cluster storage. It is not always faster than local storage.

HDFS architecture: client, NameNode, DataNodes and blocks

The four roles become clear when metadata and payload are kept separate.

Component

Keeps or does

Does not do

Example

Client

Asks for metadata and streams data

Choose placement

Reads and writes /exam/results.csv

NameNode

Owns /exam/results.csv namespace metadata and B0/B1/B2 -> DataNodes

Store file payload

Keeps permissions, factor and locations

DataNodes

Store and serve block replicas

Own the namespace

Hold 128 MiB, 128 MiB and 44 MiB

Blocks

Are fixed-size logical chunks, except a shorter final block

Manage metadata

Form B0, B1 and B2

Apache assigns namespace and block-location decisions to the NameNode. DataNodes serve client I/O, creating, deleting or replicating blocks when instructed. User data bypasses the NameNode. File details and block locations are metadata; payloads live on DataNodes.

Worked HDFS example: split 300 MiB and calculate replicated storage

Assume /exam/results.csv has logical size 300 MiB, block size 128 MiB and replication factor 3. Ignore checksums, metadata files, file-system overhead, compression and erasure coding. The last block consumes only its actual payload bytes.

  1. Number of blocks = ceil(300 / 128) = ceil(2.34375) = 3.

  2. B0 = 128 MiB and B1 = 128 MiB, so B2 = 300 - 128 - 128 = 44 MiB.

  3. Logical size remains 128 + 128 + 44 = 300 MiB.

  4. Total replicas = 3 blocks x 3 replicas = 9 block replicas.

  5. Replicated payload = (128 + 128 + 44) x 3 = 300 x 3 = 900 MiB.

  6. Redundancy beyond the logical file = 900 - 300 = 600 MiB.

In the hypothetical placement, Rack A has DN1: B0, B1, B2; DN2 and DN3 have none from this file. Rack B has DN4: B0, B2, DN5: B0, B1 and DN6: B1, B2. Check: DN1 300 + DN4 172 + DN5 256 + DN6 172 = 900 MiB.

The trap 3 x 128 x 3 = 1,152 MiB treats the final block as full. Here, final B2 contains only 44 MiB.

HDFS cluster diagram mapping the three blocks of a 300 MiB file from the NameNode to DataNodes across two racks as nine replicas.

HDFS write pipeline and read path using the same blocks

To write B0, the client asks the NameNode to create /exam/results.csv. The NameNode chooses and returns DN1, DN4, DN5. The client sends packets to DN1, which stores and forwards them to DN4. DN4 stores and forwards them to DN5. Acknowledgements return DN5 -> DN4 -> DN1 -> client. Apache calls this replication pipelining. The client does not send three independent full writes, and the 128 MiB payload never passes through the NameNode. Acknowledgements confirm each packet back through the chain before the client progresses.

To read B2, the client asks the NameNode for locations and receives DN1, DN4, DN6. It selects an appropriate replica, considering proximity, and checks the returned data with HDFS checksums. If that replica is corrupt or unavailable, it can try another. Metadata lookup goes to the NameNode, but block I/O goes directly between the client and a DataNode.

DataNode failure, heartbeat detection and re-replication

Now fail DN5. Its B0 and B1 replicas leave service, so each falls from 3 available replicas to 2. B2 remains at 3. The file stays readable because every block still has live replicas. This is under-replication, not the loss of either logical block.

DataNodes send heartbeats and block reports. Apache explains that missing heartbeats let the NameNode identify an unavailable DataNode, track under-replicated blocks and schedule new replicas. There is no universal detection time to memorise because timeout and staleness behaviour are configurable.

For this teaching repair, copy B0 from DN4 to DN6 and B1 from DN6 to DN4. The repaired maps are B0 -> DN1, DN4, DN6, B1 -> DN1, DN6, DN4 and B2 -> DN1, DN4, DN6. Real targets follow HDFS placement and storage policies, not these illustrative labels.

Two-panel diagram: DN5 fails and B0 and B1 drop to two replicas, then copies between DN4 and DN6 restore three replicas each.

Metadata persistence, checkpoints and NameNode high availability

Apache's metadata model uses FsImage as a persisted image of the namespace and EditLog to record namespace changes. A checkpoint applies accumulated edits to an image and produces an updated, consistent view. FsImage does not contain the 300 MiB payload.

This is why checkpointing by a Secondary NameNode is not the same as a hot-standby failover service. In an HA deployment using the Quorum Journal Manager, Active and Standby NameNodes share edits through JournalNodes. Only the Active handles client operations at any one time; Standby nodes maintain state for failover.

Keep three failures distinct. A DataNode failure is absorbed by the surviving replicas and repaired by re-replication. A NameNode failure without HA stops the metadata service, so the namespace becomes unreachable even though every block on every DataNode is intact. A NameNode failure with HA is taken over by the Standby, which restores the metadata service but does nothing about missing block replicas.

How exams test HDFS: five patterns and their traps

Question cue

Correct result for this example

Common wrong turn

Block count

ceil(300/128) = 3

Use floor division

Last block

44 MiB

Assume 128 MiB

Replica count

9

Answer 3

Replicated payload

900 MiB

Calculate 1,152 MiB

Failed DN5

B0 and B1 fall to 2; no block is lost

Declare the file unavailable

Namespace and block mapping point to the NameNode; payload and client I/O point to DataNodes. B0 follows client -> DN1 -> DN4 -> DN5, never client -> NameNode -> every DataNode.

"Secondary NameNode is a hot backup" is false in the checkpointing sense. "Replication factor 3 survives any three node failures" is false because survival depends on replica placement.

These cues stick faster on real questions than on definitions. Use DBMS MCQs for practice and GATE Guidance by Sanchit Sir for the exam sequence.

HDFS short version and the next step

NameNode means metadata and placement decisions.

DataNode means block payload and client I/O.

Replication means multiple copies of every block.

Heartbeat loss means the NameNode may schedule re-replication.

For a five-minute revision, recompute 300 -> 128 + 128 + 44, then 3 blocks -> 9 replicas -> 900 MiB. Redraw the DN5 failure without looking. Then explain aloud why the shorter final block changes storage. Use Zero to Hero, Complete CS Course for a broader CS fundamentals path, or the GATE guidance course above when your immediate goal is a full GATE CS sequence.