Build a Fault-Tolerant Block Store for Massive Tabular Datasets
System DesignModel answerLast updated
Design a distributed block-based file store for huge structured datasets, covering versioned metadata, caching, replica repair, locality-aware job scheduling, and resource-aware balancing.
You are asked to design a distributed storage service that holds very large structured datasets and feeds batch data-processing jobs. Do not stop at a box-and-arrow diagram. Walk through concrete request flows and failure sequences.
No cluster size, data volume, or latency target is given, so state your assumptions explicitly and avoid inventing deployment facts. Begin by clarifying:
- Are files immutable, append-only, or randomly mutable? How do jobs read them?
- Is the load mostly large sequential scans, appends, or small random reads?
- What durability and availability must survive a node or rack loss?
- Do jobs run inside this service or as clients of it? How much does data locality matter?
- Which cached data may be stale, and how is a file version identified?
Keep namespace metadata separate from large data blocks.
Part 1: Storage and cache flows. Describe how a large file is written and then read. Cover block placement, how metadata is published, and where caches sit. Address block IDs, file versions or manifests, who is the metadata authority, what a durable write acknowledgement means, how client metadata caches and block caches are invalidated or versioned, and how you keep read amplification bounded for structured (columnar or row-group) data while exploiting locality.
Part 2: Node failure and recovery. Describe failure detection, replica selection for reads, repair, and metadata availability. Cover checksums, placement across failure domains, repair prioritization, a single authoritative metadata state under failover, and how interrupted writes are cleaned up without ever exposing incomplete files.
Part 3: Jobs and load balancing. Explain how queued work is assigned and how storage and compute resources are kept balanced. Cover job and attempt identity, retries, locality-aware scheduling, output commit rules, capacity-aware placement, rebalancing under bandwidth limits, backpressure, and metrics that distinguish metadata, disk, network, and worker bottlenecks.
Hints
Hint 1
Pick a workload model first: write-once, large, mostly sequential files with optional append is a good default. It lets you make files immutable per version, which simplifies caching and replication.
Hint 2
Treat the file as a manifest (an ordered list of block IDs with checksums) published atomically by a replicated metadata service. Data is invisible until the manifest commit, which solves both interrupted writes and cache consistency.
Hint 3
For jobs, give every task a stable ID and each execution an attempt ID. Attempts write to private temporary paths, and only a single commit step promotes one winning attempt's output via the same atomic manifest publish.
Hint 4
Separate the failure story into detection (heartbeats, checksum mismatch), prioritization (fewest surviving replicas first), and throttling (repair and rebalance traffic must not starve foreground reads).
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Assumptions
I assume large files (hundreds of MB to TB), written once and read many times, with optional append creating a new file version. Reads are mostly sequential scans of column or row-group ranges, with some small footer or index reads. Jobs are clients of the store but can ask it where blocks live. I assume replication across failure domains (node, rack) and make no claim about cluster size.
Architecture
- Metadata service: a replicated group (Raft or Paxos) holding the namespace, file manifests, block-to-replica mappings, and a version number per file. One elected leader serves writes; followers can serve bounded-stale reads.
- Storage nodes: store blocks (for example 128 MB) as local files with per-chunk checksums (for example every 64 KB). They send heartbeats and block reports.
- Client library: talks to metadata for the manifest, then streams data directly to and from storage nodes. Data never flows through the metadata service.
- Scheduler: assigns job tasks to workers, ideally co-located with data.
Part 1: Write and read flows
Write
- The client asks metadata to create a file. The service allocates block IDs lazily as the client fills each block.
- For each block, the placement policy picks N replicas (default 3) spanning at least two racks, favoring nodes with free capacity.
- The client streams to the first replica, which pipelines to the second and third. Each replica verifies checksums.
- A block is durable when a write quorum (for example all 3, or 2 of 3 with background completion, depending on the durability requirement) has acknowledged it.
- On close, the client sends the full manifest (block IDs, lengths, checksums). The metadata leader commits it through the replicated log. Only then does a new file version become visible. This is the single publication point.
Read
- The client fetches the manifest at a given version, or "latest".
- It requests blocks from the closest healthy replica (same node, then rack, then remote), verifying checksums and falling back on mismatch.
Caching
- Client metadata cache: keyed by (path, version). Immutable versions never need invalidation. Only the "latest" pointer needs a short TTL or a version check, which is one cheap call.
- Block cache on storage nodes: keyed by (block ID, checksum). Block IDs are never reused, so entries cannot go stale, only be evicted (LRU or scan-resistant policies, since big scans pollute plain LRU).
- Footer and index cache: small and hot, pinned or kept separate so scans do not evict them.
Structured data: use columnar layouts with row groups aligned to block boundaries where possible. A reader fetches the footer, then only the needed column ranges, so read amplification is bounded by the projected columns rather than the full file. Align row groups so one group does not straddle two blocks on different nodes.
Part 2: Failure and recovery
Detection: heartbeats with a timeout (tens of seconds), plus a longer grace period before declaring a node dead, to avoid repair storms from transient blips. Clients also report checksum failures. A background scrubber re-verifies cold blocks.
Read during failure: clients retry on another replica, and metadata returns replicas sorted by distance and health.
Repair: the metadata service tracks each block's live replica count. Under-replicated blocks go in a priority queue, with blocks at one remaining replica first. Repair copies from a healthy source to a new node chosen by the placement policy, which restores failure-domain diversity. Repair traffic is rate-limited per node.
Corruption: a checksum mismatch marks that replica bad, triggers re-replication from a good copy, and then deletes the bad one.
Metadata availability: the replicated log gives a single authoritative state. On leader failure, a new leader is elected and the old one is fenced by term numbers, so a stale leader cannot commit. Periodic snapshots plus the log bound recovery time. Block locations can be rebuilt from storage-node block reports, so they do not need strict log durability.
Interrupted writes: since a file appears only on manifest commit, a crashed writer leaves orphan blocks with no manifest. A garbage collector removes blocks that are unreferenced and older than a grace period. Writers hold a lease, and expired leases allow cleanup. Never expose a partial manifest.
Part 3: Jobs and load balancing
Jobs: a job splits into tasks, each with a stable task ID. Every execution is an attempt with its own attempt ID. The scheduler keeps a queue, assigns tasks to workers via leases, and re-queues them when heartbeats lapse. Speculative attempts are allowed for stragglers.
Locality: prefer a worker on a node holding a replica, then the same rack, then any. Use delay scheduling: wait briefly for a local slot before giving up locality.
Output commit: attempts write to a private temporary location. On success, the scheduler picks one winning attempt and performs an atomic manifest rename or publish. Losing attempts are discarded. Commits are idempotent per task ID so retries cannot duplicate output.
Load balancing
- Placement favors nodes with lower utilization, but avoids always picking the emptiest, which would create write hotspots. Use power-of-two-choices.
- A background balancer moves blocks from nodes above the mean utilization by some threshold to those below, under a bandwidth cap, and never violates failure-domain rules.
- Hot blocks get extra replicas temporarily.
Backpressure: limit in-flight requests per client and per node, queue with deadlines, and shed or defer low-priority work (rebalancing, then repair of well-replicated blocks) before foreground reads.
Metrics: separate metadata (leader commit latency, RPC queue depth), disk (utilization, read latency), network (per-rack bandwidth, retransmits), and worker (slot utilization, task skew, locality hit rate). This separation tells you which tier is the bottleneck.
Trade-offs and common mistakes
- Single metadata leader is simple and consistent but a scaling limit. Mitigate with namespace partitioning, not by weakening consistency.
- Replication costs 3x storage. Erasure coding is cheaper for cold data but costs more on repair and small reads.
- Mistakes: routing data through the metadata service, repairing instantly on any missed heartbeat, letting repair or balancing starve foreground traffic, committing job output non-atomically, ignoring failure domains, and relying on cache TTLs where versioned immutable keys would be safe.