SwadhyAI Notes

All System Design notes

System Design · Storage Systems

Distributed File Systems

MapReduce jobs, data lakes, and training corpora need multi-terabyte files striped across commodity disks with a single hierarchical path. GFS- and HDFS-style systems solve that with a thin for metadata and many for bytes—not with a POSIX NAS dropped into every rack.

This note covers the classic architecture: large , leases, pipelined replication, rack-aware placement, and master HA myths. It is not a consumer “design Dropbox” case study (upload APIs, sharing ACLs, client sync). Those products may store blobs on object stores; here the unit of design is the cluster filesystem itself.

Client journey

1

Path → chunk IDs and locations.

2

Primary serializes mutations per chunk.

3

Data path bypasses the master.

4

Master restores replica count.

What actually happens

Files are split into large chunks so the master stores millions of chunk records instead of billions of tiny block pointers. Clients cache metadata briefly, then talk to chunkservers for bulk I/O. Heartbeats carry disk free space and chunk inventories; the master treats location maps as reconstructible soft state in the GFS design, which simplifies master recovery.

The consistency model is deliberately coarser than local POSIX. Concurrent writers, record appends, and replica failure produce defined regions that may be defined, undefined, or consistent-but-not-identical depending on the paper's rules. Batch analytics tolerate that better than databases do—which is why these systems excel at large sequential workloads.

Why chunks are large

plaintext
Suppose 10 PB cluster, 64 MiB chunks, 3× replication:
  unique data chunks ≈ 10 PB / 64 MiB ≈ 164 million
  with 3 replicas: ~492 million chunk copies on disks
  master metadata (rough): path entries + chunk map
    often tens of bytes to hundreds per chunk/file
  → metadata fits in master RAM at this grain

If chunks were 4 KiB like a local FS block:
  ~2.7 trillion blocks → master RAM explodes
  client would thrash metadata RPCs

Large chunks also:
  + amortize TCP setup and seek costs for sequential scans
  − make partial overwrites and tiny-file workloads awkward
  − cause imbalance if a few huge files dominate

Tiny-file workloads are a known weak spot: each small file still costs namespace metadata and often underfills a chunk. Systems add packing, HAR-like archives, or push small objects to a different store. Do not force a DFS into a latency-sensitive random 1 KB read product without redesigning the grain.

Read path

Diagram text: the exact Mermaid definition below preserves the nodes, labels, and connections. Enable JavaScript to view the rendered diagram.
Read the diagram definition
sequenceDiagram
    participant C as Client
    participant M as Master / NameNode
    participant D1 as Chunkserver A
    participant D2 as Chunkserver B
    C->>M: open / path → chunk IDs + locations
    M-->>C: chunk handle, replica list, version
    C->>D1: read chunk range + checksum
    alt D1 unhealthy or checksum fail
        C->>D2: retry another replica
    end
    D1-->>C: data bytes

Clients pick among replica locations using network distance (same rack preferred) and observed errors. Short-circuit reads in HDFS let a task read from its local DataNode when the scheduler placed compute near data—an explicit co-design with MapReduce / YARN-style locality.

Write path, leases, and pipelines

Diagram text: the exact Mermaid definition below preserves the nodes, labels, and connections. Enable JavaScript to view the rendered diagram.
Read the diagram definition
sequenceDiagram
    participant C as Client
    participant M as Master
    participant P as Primary
    participant S as Secondary replicas
    C->>M: allocate / renew lease for chunk
    M-->>C: primary + replica set
    C->>P: pipeline data
    P->>S: forward data
    C->>P: write request (mutation)
    P->>S: apply in order + ack
    S-->>P: ack
    P-->>C: success
    P->>M: report new version / locations as needed

Mutation serialization is per chunk via a . The primary orders writes, forwards to secondaries, and only then acks. Data flows in a so the client is not uploading three full copies sequentially. Version numbers advance so a returning node with old bytes becomes a and is dropped from the serving set until recopied.

plaintext
Lease sketch:
  master.grant(chunkId, primary, replicas, timeout)
  primary renews before expiry while writers are active
  if primary dies:
    lease expires → master picks new primary from up-to-date replicas
    stale replicas (lower version) are excluded

Record append (GFS):
  at-least-once client retry may create duplicates
  applications use checksums / opaque records to ignore padding / dups
  → designed for producers that can tolerate that contract

Placement, racks, and re-replication

policies vary, but the invariant is: replica sets should survive the failure domains you declare (disk, node, rack). is continuous background work. After a rack outage, thousands of chunks may be under-replicated simultaneously; masters prioritize based on urgency (only one copy left) and popularity.

EventDetectionRepair action
Disk / node deathMissed heartbeatsSchedule copies of hosted chunks elsewhere
Corrupt blockChecksum mismatch on read/scrubInvalidate bad copy; re-replicate from good
Stale replica rejoinsVersion / generation mismatchRemove from locations; delete or overwrite
Disk imbalanceFree-space reportsBalancer moves chunks in the background

Master durability and HA myths

The master logs namespace mutations to an edit log / operation log and periodically checkpoints an image. Classic HDFS language confuses interviews: it is primarily a checkpoint helper, not a transparent hot standby. Production HA adds a shared journal (or quorum journal nodes) plus an active/standby pair with fencing.

Is the master a single point of failure?

Operationally yes if you run one without HA. Architecturally the design concentrates metadata so the data plane stays simple. Mitigate with HA, fast restart from checkpoints, and keeping the master off the byte path so load is RPC/metadata bound, not disk-bandwidth bound.

How does the master scale?

Vertical RAM for metadata, federation (multiple namenodes owning path subspaces), and observer/read replicas for metadata read scale. Chunkservers scale horizontally with disks almost linearly for sequential throughput.

Why not full POSIX semantics?

Strict POSIX locking and coherent caches across thousands of nodes destroy throughput. Analytics runtimes prefer immutable inputs, rename-for-publish, and explicit consistency rules over transparent single-node illusions.

Append-heavy workloads and immutability

MapReduce and lake-house pipelines lean on that pattern: tasks write temporary paths, then atomically rename into a committed directory the next job lists. Concurrent random updates inside a multi-gigabyte file are possible but rare in the sweet spot—the lease primary becomes a hotspot, and readers must understand which byte ranges are defined.

When a product needs mutable objects with HTTP semantics, an object store (or a KV/blob layer) is usually the clearer abstraction. Keep the DFS where hierarchical bulk datasets and compute locality dominate.

plaintext
Common publish pattern:
  write  /tmp/job_42/part-0000
  ...
  rename /tmp/job_42  →  /warehouse/table/dt=2026-04-10/

Readers listing the date partition either see nothing or the full set
(assuming rename of the directory is atomic in the namespace).

Avoid:
  many clients overwriting overlapping ranges of the same open file
  without an external coordination story

Trade-offs to weigh

Large chunks vs small-file friendliness

Metadata and sequential scan efficiency versus wasted space and awkward random I/O for tiny objects.

3× replication vs erasure coding

Replication is simple and repair-friendly; encoding saves capacity at the cost of repair CPU/network and more complex degraded reads.

Central master vs distributed metadata

Simpler correctness and operations versus scaling limits; federation and object stores push metadata out differently.

Cross-rack durability vs write locality

Surviving rack loss costs cross-rack bandwidth on every pipeline write.

DFS vs object store vs local FS

LayerUnitTypical APIStrength
Local FSinode + blocksPOSIXLow latency on one machine
GFS/HDFS-style DFSfiles / chunksDFS client / FUSE-ishHuge sequential datasets, locality
Object storeobjects / keysHTTP PUT/GETSimple durable blobs, multi-tenant

Interviews often blur these. Say which API and consistency contract you need first. Many modern lakes use object storage under table formats; the GFS paper still teaches the control-plane / data-plane split cleanly.

Choosing and explaining distributed file systems (GFS/HDFS-style)

A complete explanation connects the mechanism to a requirement. Describe what improves when you introduce it, which new failure cases become possible, and how you would know that the trade-off is worthwhile.

Explain the core idea

A master owns namespace and chunk maps; clients move bulk bytes directly with chunkservers.

Large chunks keep metadata finite; leases and pipelines serialize and replicate writes.

Heartbeats drive re-replication and stale-replica exclusion via version numbers.

When it belongs

Batch analytics need petabyte sequential files with commodity disks.

You must explain metadata vs data path separation under failure.

Placement and rack awareness are part of the durability story.

How it fails

Master unavailability stalls namespace operations even if bytes exist.

Replication storms after correlated failures saturate networks.

Stale replicas serving old versions if generation checks are skipped.

Trade-offs to weigh

Replica count / erasure coding versus capacity and repair cost.

Chunk size versus tiny-file efficiency and metadata size.

Strict POSIX illusion versus throughput-oriented consistency.

Common misunderstandings

Calling the classic secondary namenode a hot standby HA solution.

Putting the master on the bulk data path.

Designing a DFS when an object store API is what the product actually needs.

Wrap-up

GFS/HDFS-style systems are a deliberate trade: centralize metadata, decentralize bytes, use large grains, and document a consistency model that batch systems can live with. Once you need POSIX locks or millisecond random reads, change the system—do not stretch chunk leases forever.

Key takeaway

Master for catalog, chunkservers for cargo, leases for writers, versions for staleness, racks for failure domains. That is the durable skeleton of a distributed file system interview answer.