SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
  • Block Storage
  • Distributed File Systems
  • Object Storage
  • Erasure Coding
  • Storage Tiers (Hot, Warm, Cold)
  • RAID
  • Compression and Deduplication
  • File Storage (NFS)
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Data and Storage/Storage Systems

Distributed File Systems

One big file system spread over many machines (HDFS, GFS).

โฑ 14 min readAdvancedInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A distributed file system (DFS) makes many machines look like one huge file system. Big files are cut into chunks, and each chunk is stored on several machines.

  • One master (the name node in HDFS) knows where every chunk is. Many chunk servers (data nodes) hold the actual bytes.
  • Every chunk has copies (usually 3). When a machine dies, the master copies the missing chunks to other machines.
  • Built for very large files, read in long streams, on cheap machines that fail often. Examples: GFS (Google) and HDFS (Hadoop).

02Concept: What is it?

One disk can hold a few terabytes. A data set can be petabytes. And one machine can be read at only a few hundred MB per second. To handle more data and more speed, we need many machines working together.

A distributed file system hides this. You write a file in a path like /logs/2026/12/01.log. Behind the scenes the system splits it into big pieces (chunks in GFS, blocks in HDFS, 64 MB in the GFS paper and 128 MB by default in modern HDFS), spreads them over many servers, and keeps extra copies.

With so many cheap machines, failure is normal. Disks break, servers crash, racks lose power. So the design assumes failure and repairs itself.

The two kinds of machines
๐Ÿ™‹Clientreads or writes a file
โ†’โ†“1. where is the chunk?
โ†”2. read the bytes
๐ŸงญName node / masterfile tree + chunk map
๐Ÿ–ฅ๏ธChunk server 1chunks 1, 4
๐Ÿ–ฅ๏ธChunk server 2chunks 1, 2
๐Ÿ–ฅ๏ธChunk server 3chunks 2, 4
Metadata (small) Data (huge)
The master holds the map (metadata). The chunk servers hold the data. Clients get the map once, then talk to chunk servers directly.
๐Ÿง The data never flows through the master
The master only answers "which servers hold chunk 7?". The client then reads from a chunk server. This keeps the single master from becoming a bottleneck for data.

03Real-Life Example

๐ŸตA Big Book Split Across Libraries
A giant encyclopedia is too large for one shelf. So you cut it into 100 volumes and place each volume in 3 different libraries in the city. A head librarian (the master) keeps a card index: "volume 7 is in the East, North and West library". If a library burns down, the head librarian notices, finds volumes with fewer than 3 copies, and orders new copies to be made at other libraries. Readers ask the head librarian once, then walk to a library to read.
Libraries
Distributed file system
A volume of the encyclopedia
A chunk or block of a file
Three libraries each hold a copy
Replication factor 3
Head librarian with the card index
Name node / master (metadata)
A library
A chunk server / data node
Librarians report 'we are open' daily
Heartbeats and block reports
Ordering new copies after a fire
Re-replication
Copies in different cities
Rack-aware placement
Writing a file (the simplified path)
๐Ÿ™‹Clienthas a 300 MB file
โ†’โ†“ask
๐ŸงญMasterpicks 3 servers per chunk
โ†’โ†“stream
๐Ÿ–ฅ๏ธServer 1
โ†’โ†“pipeline
๐Ÿ–ฅ๏ธServer 2
โ†’โ†“pipeline
๐Ÿ–ฅ๏ธServer 3

04Why Do We Need It?

๐Ÿ“Huge capacity
Add machines to add space. A cluster can hold petabytes.
๐Ÿš€High total speed
Many machines read their chunks at the same time. A big scan finishes much faster.
๐Ÿ›ก๏ธSurvives failure
Copies mean a dead disk or server does not lose data.
๐Ÿ’ธRuns on cheap hardware
Software handles the failures, so normal commodity servers are enough.
๐ŸššMove code to data
A job runs on the machine that already holds the chunk, so less data crosses the network.
๐ŸงฐOne simple view
Programs see one folder tree, not hundreds of disks.
When data is too big for one machine, split it, copy it, and let a small master remember where everything is.

05Where Do We Use It?

๐Ÿ˜Big data and Hadoop
HDFS stores the data that MapReduce, Spark and Hive process.
๐Ÿ”ŽSearch indexes and web crawls
GFS was built for Google's crawl data and index files.
๐Ÿค–Machine learning
Huge training sets are read in long scans by many workers.
๐Ÿ“œLogs and analytics
Days of logs are written once and read many times.
๐ŸงฌScience data
Large files for genomics, simulations and satellites (Lustre, GPFS and others in HPC).
๐Ÿ—ƒ๏ธData lakes
Raw data kept for later analysis, on HDFS or on object storage.

06Types / Parts / How It Works

The parts of a typical design (GFS and HDFS)

PartJobNotes
Name node / masterKeeps the file tree and the map from each file to its chunks and their locationsMetadata is held in memory for speed. It is a single point of failure unless you add a standby.
Chunk server / data nodeStores chunks as ordinary files on its local disks, serves reads and writesSends heartbeats and block reports to the master.
Client libraryAsks the master for locations, then reads and writes directly with chunk serversCan cache locations.
Edit log + checkpointA saved log of changes to the file tree, plus snapshots of itLets the master restart after a crash.
Standby / HA name nodeA hot backup of the master (HDFS HA with a quorum journal)Takes over in seconds if the active one dies.
One file, four chunks, three copies each
Rack A
๐Ÿ–ฅ๏ธS1chunks 1, 3
๐Ÿ–ฅ๏ธS2chunks 2, 4
๐Ÿ–ฅ๏ธS3chunks 1, 2
Rack B
๐Ÿ–ฅ๏ธS4chunks 3, 4
๐Ÿ–ฅ๏ธS5chunks 1, 3
๐Ÿ–ฅ๏ธS6chunks 2, 4
Chunk servers are in two racks. Copies are spread so losing one machine, or even one rack, still leaves every chunk.

The self-healing loop

StepWhat happens
1. HeartbeatsEvery chunk server tells the master it is alive every few seconds (3 s in HDFS by default).
2. Failure noticedNo heartbeat for a long time (about 10 minutes by default in HDFS) and the server is marked dead.
3. Find the damageThe master looks up every chunk that server held and finds those below the target number of copies.
4. Re-replicateThe most endangered chunks are copied first, from a surviving copy to a healthy server, at a limited rate.
5. Back to normalEvery chunk again has its full number of copies.
DFS (HDFS, GFS)
Big files, streaming
  • Large chunks, big sequential reads
  • Write once, append, rarely edit
  • Compute can run next to the data
  • A master tracks the map
Object storage (S3)
Objects with keys
  • HTTP API, no folders
  • Separate compute and storage
  • Near-endless and cheap
  • Higher latency per request
VisualizerChunks, copies and self-healingClick a chunk server to crash it and watch the name node copy chunks to other servers. Try 1 copy (loses data), then 3 copies. Crash two servers one after another.
Replication factor (copies of every chunk)
Name node
knows where every chunk is
File: 8 chunks x 128 MB = 1024 MB. Click a server to crash or revive it. Hover a chunk to see its copies.
chunk 1: 3/3
chunk 2: 3/3
chunk 3: 3/3
chunk 4: 3/3
chunk 5: 3/3
chunk 6: 3/3
chunk 7: 3/3
chunk 8: 3/3
Dashed pulsing squares are copies in flight. Colours and numbers are chunk numbers.
Servers alive
6/6
Chunks safe
8/8
full copies
Under-replicated
0
at risk
Lost
0
no copy left
Space used
3072 MB
3x the file size
Healthy. Every chunk of the file lives on several chunk servers. Click a server to crash it.

A simplified model of HDFS or GFS. The name node keeps the map from chunk to servers. Chunk servers store the data and send heartbeats. Placement is rack aware: one copy in one rack and two in the other, so losing a whole rack still leaves a copy. Real clusters wait for a heartbeat timeout (about 10 minutes in HDFS by default) and then copy at a limited rate. Try 1 copy and crash a server: data is lost for good. Try 3 copies and crash two servers one after the other, giving it time to re-replicate in between.

07How to Use It / Steps / Implementation

Reading and writing, step by step

  1. 1
    Read: ask the master
    The client sends a file name and an offset. The master returns the chunk number and the servers that hold it.
  2. 2
    Read: go to a chunk server
    The client reads the bytes from the nearest copy. Many clients can read different chunks in parallel.
  3. 3
    Write: master picks servers
    For a new chunk the master chooses several servers. A common rule: one copy near the writer, others in a different rack.
  4. 4
    Write: pipeline the data
    The client sends data to the first server, which passes it to the second, which passes it to the third. This uses each machine's network well.
  5. 5
    Write: confirm
    When all copies are stored, the write is acknowledged. HDFS keeps the file as write-once, with append only. GFS also supports record append.
  6. 6
    Heal in the background
    Heartbeats and block reports let the master spot dead servers and bad copies. Checksums catch silent corruption. It re-replicates by itself.
  7. 7
    Balance and tune
    Run a balancer so no server is far fuller than the rest. Choose the block size and replication factor that match your files.
๐Ÿ’กFew big files beat many small files
The master keeps information about every file and chunk in memory (roughly a hundred and fifty bytes or more per object in HDFS). Millions of tiny files can fill the master's memory long before the disks are full. Combine small files into larger ones (for example with container file formats).
โš ๏ธNot for everything
A DFS like HDFS is not built for low-latency random reads, many small files, or editing the middle of a file. Use a database, block storage or an object store with caching for those jobs.

08Key Terms to Know

TermMeaning in easy words
Chunk / blockA big fixed-size piece of a file (64 MB in GFS paper, 128 MB by default in HDFS)
Name node / masterThe machine that stores the file tree and the location of every chunk
Chunk server / data nodeA machine that stores chunks on its disks
MetadataInformation about the data: names, sizes, chunk locations, permissions
Replication factorHow many copies of every chunk exist (default 3 in HDFS)
HeartbeatA small regular message that says 'I am alive'
Under-replicatedA chunk with fewer live copies than the target
Re-replicationMaking new copies of chunks after a failure
Rack awarenessPlacing copies in different racks so one rack failure cannot kill them all
ChecksumA number that detects damaged data, checked on every read
Edit log / checkpointThe saved changes and snapshots of the metadata, used to restart the master
Data localityRunning the work on the machine that already holds the data

09Pros, Cons and Trade-offs

โœ… Pros
  • Scales to petabytes by adding machines
  • Very high combined read speed
  • Survives machine and rack failures
  • Runs on cheap hardware
  • Compute can move to the data
โš ๏ธ Cons
  • The master is a bottleneck and a risk (needs HA)
  • Poor with many small files
  • High latency for random access
  • Mostly write-once or append-only
  • 3 copies means 3x the storage

Trade-offs

ChoiceWe gainWe lose
More copiesSafer data and more read optionsMore disk space and write traffic
Fewer copiesCheap storageA single failure can lose data
Large chunksSmall metadata, fast streamingWaste for small files, less parallelism for small jobs
Small chunksMore parallelism, finer balanceA bigger map in the master
Single masterSimple, consistent view of the file treeA scaling limit and a failure risk
Replication vs erasure codingReplication: simple and fast readsReplication costs 3x. Erasure coding costs about 1.5x but repair is heavier.

10Common Problems and Mistakes

Common mistakes

  1. Storing millions of tiny files. The master runs out of memory and everything slows.
  2. No standby master. One crash stops the whole cluster. Use an HA setup.
  3. Replication factor 1 for important data. A single disk failure loses it for good.
  4. Ignoring racks. All copies in one rack die together when a switch fails.
  5. Treating it like a normal database. It is slow for random small reads and writes.
  6. Letting the cluster get too full. With no free space, re-replication cannot finish.
  7. Unbalanced servers. New servers stay empty and old ones fill up. Run the balancer.

Things to watch

๐ŸŒŠRe-replication storms
Losing a big node floods the network with copies. Rates are limited on purpose.
๐Ÿ•ณ๏ธSilent corruption
A disk can flip bits. Checksums find it, and a good copy replaces the bad one.
๐Ÿง Metadata growth
The file count limits the cluster as much as the disks do.
๐Ÿ”ŒCorrelated failures
A power or network problem can take out many machines at once.

11Real-World Examples

๐Ÿ”Google File System (GFS)
The 2003 paper that started it: one master, many chunk servers, 64 MB chunks, 3 copies. It was later replaced inside Google by Colossus.
๐Ÿ˜Hadoop HDFS
The open-source cousin used by Hadoop and Spark. Very common for on-premises data lakes.
๐ŸŒฉ๏ธColossus, Azure Data Lake, EMRFS
Cloud-scale descendants and cloud connectors that offer the same style of big-file storage (general idea).
๐ŸงฒCeph, GlusterFS, Lustre, GPFS
Other distributed file systems with different designs. Lustre and GPFS are common in supercomputers.
๐Ÿ“šFacebook's Haystack and f4
Photo stores built for many files and a different access pattern (general idea).
๐ŸงชSpark and Hive jobs
Run next to HDFS data to avoid copying huge files over the network.
๐Ÿ“Note
These are general ideas. Block sizes, defaults and the details of each product change across versions.
Mini case: a node dies at night
๐Ÿ’€Server diesholds 2 TB of chunks
โ†’โ†“no heartbeat
๐ŸงญMasterlists lost copies
โ†’โ†“copy
๐Ÿ–ฅ๏ธOther serversmake new copies
โ†’โ†“done
โœ…3 copies again
No one is paged. The cluster repairs itself, and the job that is running just reads a different copy.

12Related Topics to Read Next

Block Storageโ†’

One server, one raw disk: the simpler layer a DFS builds on.

Object Storageโ†’

The cloud alternative for huge files, over HTTP.

Erasure Codingโ†’

A way to cut the 3x cost of replication.

Replicationโ†’

The same idea of copies, for databases.

Consistent Hashingโ†’

Another way to spread data over many machines.

Single Point of Failure (SPOF)โ†’

The master is one, which is why HA masters exist.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • โœ”What: many machines acting as one huge file system.
  • โœ”Parts: one master with the chunk map, many chunk servers with the bytes.
  • โœ”Chunks: 64 to 128 MB, copied 3 times, in different racks.
  • โœ”Read: ask the master where, then read from a chunk server. Data skips the master.
  • โœ”Failure: heartbeats stop, master notices, re-replicates under-copied chunks.
  • โœ”Best for: huge files, long reads, write-once or append. Batch analytics.
  • โœ”Weak at: many small files, random access, low latency, and master load.
  • โœ”One line: โ€œCut big files into chunks, keep 3 copies, and let a small master heal the cluster.โ€
โ† Previous
Block Storage
Next โ†’
Object Storage