CMD Guide
HomeSystem DesignDistributed File System

Architecture of a Distributed File System

A distributed file system chops every file into fixed-size blocks, stores each block as an ordinary file on many commodity machines, and keeps a separate, tiny service that remembers only which blocks make up which file and which machines hold each replica — so the metadata service handles lookups while the bulk bytes stream directly between the client and the storage machines. That split of a small control plane from a fat data plane is the whole architecture; everything else (replication, rebalancing, recovery) hangs off it.

The names differ by system but the roles are identical: HDFS calls them NameNode (metadata) and DataNodes (block storage); Google File System calls them master and chunkservers. HDFS blocks default to 128 MB, GFS chunks to 64 MB — orders of magnitude larger than a local filesystem's 4 KB block, precisely so one small master can index petabytes.

Why the two planes are physically separate

The reason bytes must not flow through the metadata server is arithmetic. A NameNode holds the entire namespace in RAM: roughly 150 bytes per file, block, and directory object. A machine with 64 GB of heap can index on the order of 400 million objects — but only if it is doing lookups, not shovelling data. If every read and write went through it, its network card, not its memory, would cap the cluster at one machine's bandwidth. By handing the client a list of DataNode addresses and then stepping out of the path, the master's load scales with the number of operations, while throughput scales with the number of DataNodes. Add 500 DataNodes and aggregate bandwidth grows 500×; the NameNode barely notices.

diagram
diagram

Tracing one write, end to end

Say a client writes a 300 MB file /logs/2026-07-03.parquet to HDFS with the default 128 MB block size and replication factor 3. The file becomes three blocks (128 + 128 + 44 MB), and each block is written independently. Here is the trace for the first block. Note that the master is contacted once per block, not once per byte.

StepWho → whoWhat happens (real values)
1Client → NameNodecreate("/logs/2026-07-03.parquet"). NameNode checks permissions, that the path is free, records the file in the namespace, and takes a lease so no one else writes it.
2Client → NameNodeaddBlock(). NameNode mints blk_1073, gen-stamp 42 and, using rack awareness, returns a placement pipeline: [DN-A (rack1), DN-B (rack2), DN-C (rack2)] — one local-ish replica, two on a second rack.
3Client → DN-A → DN-B → DN-CClient opens a TCP pipeline to DN-A only; DN-A connects to DN-B; DN-B to DN-C. Data now flows client→A→B→C.
4along the pipelineThe 128 MB block is split into 64 KB packets; each packet is a chain of 512-byte chunks each carrying a CRC-32C checksum. DN-A forwards a packet to DN-B the instant it arrives — it does not wait for the whole block.
5DN-C → DN-B → DN-A → ClientAcks flow back up the pipeline. A packet is "done" only when all three nodes have it on disk. The client keeps a sliding window of unacked packets in flight.
6DataNodes → NameNodeAs each replica finishes, the DataNode sends a blockReceived report. The NameNode now knows blk_1073 lives on A, B, C.
7Client → NameNodeBlock full → back to step 2 for block 2, then block 3. After the last block, complete() closes the file and releases the lease. The write is durable once min-replication (default 1, often set to 2) acks land.

A read is the mirror image and even cheaper: the client asks the NameNode for the block list once, gets {blk_1073: [DN-A, DN-B, DN-C]}, then reads each block from the closest replica (same node > same rack > remote), verifying every 512-byte chunk against its checksum and failing over to the next replica if a checksum is wrong.

diagram
diagram

File operations beyond write: open, close, rename

The write pipeline dominates the interview trace, but a DFS also has to make everyday filesystem operations behave sensibly across replicas.

Why this matters in design rounds: "rename a 1 TB file" is a classic trap. In a local filesystem it may copy bytes; in a centralized-metadata DFS it is an O(1) namespace update. Conversely, "concurrent writers rename the same file" is undefined or last-writer-wins, which is why leases and single-writer rules exist.

Pitfalls

When to use this architecture — and when not to

The centralized-metadata, block-replicated design (HDFS, GFS) is the right call when you have a modest number of enormous, append-mostly files read by high-throughput batch jobs — log/event lakes, ML training corpora, MapReduce/Spark inputs — and you value sequential throughput over latency. The decision signals: files measured in GB not KB, write-once-read-many access, and co-located compute that wants data locality.

Weigh it against the named alternatives:

Rule of thumb: choose centralized-metadata DFS for petabyte-scale, batch-throughput workloads on your own hardware; prefer an object store when you can offload operations to a cloud and can live with object (not file) semantics; prefer Ceph-style hashing when central metadata is itself the scaling wall.

Takeaways


Sources: Ghemawat, Gobioff & Leung, "The Google File System" (SOSP 2003); Shvachko et al., "The Hadoop Distributed File System" (MSST 2010); the Apache Hadoop HDFS Architecture & HA documentation; Weil et al., "Ceph: A Scalable, High-Performance Distributed File System" (OSDI 2006). Re-authored/Deepened for this guide.

Distributed file system read-path trace

StepComponentAction
1ClientRequests /data/foo.txt
2NameNodeReturns block IDs and closest DataNode locations
3DataNodeStreams the nearest replica to the client
4ClientVerifies block checksums; asks another replica on mismatch
5ClientMarks the bad DataNode dead locally and re-requests the block from the next replica in the location list

When NOT to build a custom DFS

Interviewer follow-ups & drills

  1. Why separate metadata and data planes? Metadata is latency-sensitive and consistent; data is throughput/bandwidth.
  2. Ops: namenode/master CPU, under-replicated blocks, rebalance bandwidth, client tail latency.
  3. Drill: 3-way block replication, one disk dies — what must the master do? Mark under-replicated, schedule re-replication without blocking all reads.
🤖 Don't fully get this? Learn it with Claude

Stuck on Architecture of a Distributed File System? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Architecture of a Distributed File System** (System Design) and want to truly understand it. Explain Architecture of a Distributed File System from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Architecture of a Distributed File System** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Architecture of a Distributed File System** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Architecture of a Distributed File System** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes