Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Distributed file systems

Practical study notes on distributed file systems: goals, architectures, naming, caching, replication, consistency models, and common exam examples (NFS, AFS, GFS/HDFS).

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Distributed file systems (DFS) let many machines share files as if they were on one machine. Engineers use them when building large-scale storage (web services, cloud, big-data platforms) because DFS provide shared storage, scalability, data locality, and fault tolerance across many servers.

Key ideas

Start from first principles and definitions. Define every term before use.

  • Distributed file system (DFS) — a system that provides file access and file management services to multiple clients across a network while hiding the distribution of storage resources. Important properties: sharing, concurrency, failure-handling, and naming.

  • Transparency — hiding some detail from the user. Types used in DFS: location transparency (file path hides server location), replication transparency (user does not see multiple replicas), and concurrency transparency (concurrent access looks like serial access under some semantics).

  • Mount — the operation by which a client makes a remote filesystem accessible at a local directory path. Define and draw: a client machine, a mount point folder, arrow to remote server labelled "mount".

  • File handle — a server-issued opaque identifier that the client uses instead of the pathname for subsequent operations (avoids repeated name lookup).

  • Stateful vs stateless server — stateful server keeps information across client calls (e.g., locks, open file descriptions). Stateless server does not keep per-client state (e.g., original NFS v2). Assumption affects failure recovery and caching strategies. Stateless designs require idempotent operations and at-least-once RPC handling so clients can safely retry after timeouts.

  • Caching — storing data copies close to clients to reduce latency and load. Client-side cache keeps file data or metadata locally; cache must be kept coherent with updates elsewhere.

  • Coherence vs Consistency — coherence often refers to cache correctness (no stale data under some semantics). consistency model is the formal contract specifying the behaviour of reads and writes across the whole system (see file semantics below).

  • Replication — keeping multiple copies of data on different servers to increase availability and read throughput and to tolerate failures. We use replication protocols (primary-backup, chain replication, quorum systems) to keep replicas synchronized.

  • File semantics — precise guarantees for the result of reads and writes in concurrent systems. Common file semantics definitions used in exams:

    • UNIX semantics — after a write completes, a subsequent read (by any client) returns the written data (i.e., global serialization of writes consistent with single-copy memory). This is strong and expensive to implement in DFS.
    • Session semantics — a client's own reads within a session see its own writes; other clients may see writes only after the file is closed or after some server action.
    • Close-to-open semantics (a common weak model) — updates propagate on file close or explicit sync; between close and open other clients may not see changes.
  • Consistency protocols — methods to maintain coherent data: callbacks/leases, validation on access, write-through vs write-back, and quorum protocols.

    • Callback (or callback promise) — server tells the client it is caching a block and promises to inform (invalidate) the client if the block changes elsewhere. This needs server to be stateful and to track which clients hold callbacks.
    • Lease — time-limited callback: server grants a lease to a client for a time T; client may cache until lease expires.
    • Quorum system (R, W, N) — with N replicas, a read must contact at least R replicas and a write must update at least W replicas; the read must reconcile versions (e.g., choose the highest timestamp among the R responses or require majority agreement). For correctness: R + W > N (read–write intersection) and W > N/2 (write–write intersection).
  • NFS (Network File System) — historically an example of a DFS. Older NFS versions aimed to be stateless (simpler recovery) and relied on close-to-open semantics and client validation (stat() checks) rather than callbacks.

  • AFS (Andrew File System) — used server callbacks to support aggressive client caching with better performance; server remembers which clients cached which files and invalidates them on write.

  • GFS/HDFS — designs for large data and sequential access. Separate metadata server (small, keeps namespace and block locations) from data nodes (store large blocks). Files cut into large fixed-size blocks (e.g., tens or hundreds of megabytes) and replicated (replication factor, e.g., 3). Writes are typically streamed to replicas in a pipeline. These systems are optimized for write-once, read-many workloads and historically avoid in-place random writes (supporting streaming writes/append instead).

  • Fault tolerance and recovery — DFS must handle server crashes and network partitions. Techniques: replication with re-replication, master failover (metadata server backup), and checksumming to detect corruption.

  • Diagram to draw for exams (describe exactly): draw three boxes: "Client", "Metadata server (master)" and three "Data nodes". Label an arrow from Client to Metadata server: "get block locations / file metadata". Then arrows from Client to Data nodes: "read block / write pipeline". Show replication arrows between Data nodes to indicate multiple replicas.

Derivations universities ask for: show why R + W > N ensures a read sees the latest write. Assume last completed write was applied to W replicas; at least one of the R readers must contact a replica that has the latest write because R + W > N guarantees overlap.

Proof (step-by-step):

  1. Suppose there are N replicas. A write updates W replicas. A subsequent read reads from R replicas.
  2. If R + W > N, then the sets of replicas touched by the read and the write must overlap (pigeonhole principle). Therefore the read obtains at least one response from a replica updated by the write; if the read selects the newest version among the R responses (e.g., by timestamp/epoch), it observes the write's effect (assuming replicas are accessible). QED.

Formulas

Expected read latency = p * L_local + (1 - p) * L_remote

  • p = probability of cache hit (unitless)
  • L_local = latency for local cache read (s)
  • L_remote = latency for remote read (s)
  • Applies when reads either hit local cache or else go to remote server.

R + W > N

  • R = read quorum size (integer)
  • W = write quorum size (integer)
  • N = number of replicas (integer)
  • Condition ensures read-write intersection so that reads see latest completed writes.

W > N / 2

  • Ensures write-write intersection so two concurrent writes must overlap in at least one replica.

System throughput (single-server bottleneck) ≈ 1 / L_service; per synchronous client throughput ≈ 1 / (L_request + L_service)

  • L_request = network round-trip time + processing overhead (s)
  • L_service = service time per request (s)
  • Use 1 / L_service for aggregate server capacity; use 1 / (L_request + L_service) for a single client issuing one outstanding request at a time.

(There are no universal SI constants required. Verify any system defaults separately.)

Worked examples

Example 1 — Expected read latency with client caching Problem: A client has cache-hit probability p = 0.7. Local cache read time L_local = 1 ms (0.001 s). Remote read (including network) L_remote = 50 ms (0.05 s). Compute expected read latency. Steps:

  1. Formula: Expected read latency = p * L_local + (1 - p) * L_remote.
  2. Substitute: = 0.7 * 0.001 + 0.3 * 0.05.
  3. = 0.0007 + 0.015 = 0.0157 s. Answer: 0.0157 s (15.7 ms).

Example 2 — Quorum sizes for replication Problem: N = 5 replicas. Choose minimal integer W and R to satisfy R + W > N and W > N/2. Provide one valid solution. Steps:

  1. Compute N/2 = 2.5, so minimal integer W > 2.5 is W = 3.
  2. Now pick minimal R such that R + 3 > 5 => R > 2 => minimal R = 3.
  3. So R = 3, W = 3 satisfies R + W = 6 > 5. Answer: Use R = 3 and W = 3 (reads and writes must touch 3 replicas each).

Example 3 — HDFS write pipeline (algorithm trace) Problem: Describe the steps a client follows to write a file in HDFS with replication factor 3. Answer (step-by-step):

  1. Client asks NameNode (metadata server) for block allocation for the file (gets list of DataNodes for each block).
  2. For a block, NameNode returns three DataNodes [DN1, DN2, DN3].
  3. Client opens a TCP connection to DN1; DN1 opens to DN2; DN2 opens to DN3 (pipeline chain).
  4. Client streams block data to DN1; DN1 forwards to DN2; DN2 forwards to DN3. Each node writes to local disk and replies with ack upstream.
  5. When all replicas ack, client considers the block written.
  6. On NameNode failure, a backup NameNode or high-availability mechanism takes over (describe as needed for exam).

Common mistakes

  • Confusing file semantics: UNIX semantics is stronger than session semantics; don’t claim session semantics gives immediate visibility to other clients.
  • Forgetting network partition effects: availability and consistency trade-offs (CAP) are important — DFS choices depend on what is prioritized.
  • Assuming default numbers (e.g., HDFS block size or replication factor) without checking current system defaults — these change over time.

For your exam

Kinds of questions:

  • Definitions (e.g., define DFS, cache coherence, file semantics).
  • Short notes (compare NFS and AFS, explain callbacks vs validation).
  • Derivations/proofs (show R + W > N implies read-write intersection).
  • Numericals (compute expected latency with caching, choose quorum sizes).
  • Algorithms/sequence diagrams (trace how a client reads/writes in NFS, AFS, HDFS, or explain re-replication after node failure).
  • Diagrams (draw client, metadata server, data nodes, and show read/write flow).

What full-marks answers include:

  • Precise definitions (bold terms in answers helps clarity).
  • Clear assumptions (stateless/stateful, network reliability, synchronous vs asynchronous replication).
  • Correct diagrams with labels (client, metadata, data nodes, arrows with operation names like "getBlockLocations", "stream data").
  • Step-by-step protocols (who contacts whom, what messages are sent, when write is considered committed).
  • For proofs, show each logical step (e.g., for quorum overlap use counting argument).

Quick check

  1. What is the difference between a callback and a lease?
  2. State the quorum condition that ensures a read sees the latest completed write.
  3. Why do DFS like HDFS use large block sizes (tens or hundreds of MB) instead of small blocks?

Answers: 1) A callback is a server promise to inform specific clients on changes (event-driven invalidation); a lease is a time-limited promise to cache (expires after T). 2) R + W > N (and typically W > N/2 for write-write intersection). 3) Large blocks reduce metadata overhead at the metadata server, increase throughput for large sequential reads/writes, and reduce network and seek overhead for big-data workloads.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?