Architect a Scalable Storage Cluster for Huge Files Across Many Machines
System DesignModel answerLast updated
Design a cluster-based file storage system from a vague prompt, defining workload, guarantees and scale first, then covering metadata, data placement, I/O paths and failure handling.
You are asked to design a distributed file system: a storage service that spreads files across many commodity machines and presents them to clients as a single namespace.
The prompt is deliberately short. No workload, scale or guarantees are given, so part of the task is to decide and justify them yourself before you design.
Cover the following in your answer:
- Scoping. Which questions would you ask, and which assumptions would you commit to? Think about:
- The dominant workload: a modest number of very large files read and appended in bulk, or a huge number of small files with random access.
- The semantics: full POSIX (in-place overwrites, rename, locking) or a simpler write-once / append-only model.
- Scale: total bytes, number of files, number of concurrent clients.
- Durability and availability goals, and which failures must be tolerated (disk, machine, rack, data center).
- Consistency expectations for reads after writes and for directory operations such as rename.
- Architecture. How do you separate the metadata layer from the data layer, and how does each scale and stay available?
- Data placement. Block size, replication versus erasure coding, and awareness of failure domains.
- Read, write and append paths, including how concurrent writers are coordinated and what clients observe.
- Failure handling. Failure detection, restoring lost redundancy, integrity checking, and recovery from a failed metadata node.
- Operations. Many small files, rebalancing, reclaiming space from deleted data, and monitoring.
Be explicit about trade-offs and tie each major decision back to the requirements you chose.
Hints
Hint 1
Start by committing to a workload. Large, mostly sequential files with append-heavy writes lead to very different choices (big blocks, relaxed semantics) than a general-purpose POSIX file system.
Hint 2
Keep the metadata path separate from the data path: a small, strongly consistent service decides where blocks live, while clients stream bytes directly to and from storage nodes so the metadata service never carries bulk traffic.
Hint 3
Ask what happens when each component dies: a storage node, a whole rack, the metadata leader. For each, say how it is detected, what is repaired, and what the client sees in the meantime.
Hint 4
Estimate metadata memory: number of files and blocks multiplied by roughly 100-200 bytes each tells you when a single metadata node stops being enough and the namespace must be partitioned.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Scoping and assumptions
I would state these up front and design against them:
- Workload: analytics and batch pipelines. Files are large (hundreds of MB to TB), written once or appended, then read mostly sequentially. Small random in-place updates are not a goal.
- Semantics: write-once plus append, no in-place overwrite, no byte-range locks. Rename and delete of files and directories must be atomic.
- Scale: roughly 100 PB of raw capacity, around 1 billion files, thousands of storage nodes, and tens of thousands of concurrent clients.
- Durability and availability: at least 11 nines of durability for committed data. Survive any single disk, machine or rack failure with no data loss and no read outage. Cross-data-center replication is an optional extension.
- Consistency: strong consistency for metadata operations (create, rename, delete, list). Once a write or append is acknowledged, any later read sees it.
Everything below follows from these choices, and a different answer (for example small files with random access) would change block size, caching and the metadata design.
2. Architecture overview
Two planes:
- Metadata service: namespace tree, file-to-block mapping, block locations, permissions, leases.
- Storage nodes: hold immutable-ish blocks on local disks and serve them over a streaming protocol.
Clients ask the metadata service where to read or write, then talk directly to storage nodes. Bulk data never flows through the metadata service, which is the key to scaling.
3. Metadata layer
- Files are split into fixed-size blocks, typically 128-256 MB. Large blocks keep the number of blocks, and therefore metadata and client round trips, small.
- Memory estimate: 1 billion files with a few blocks each is about 3-5 billion objects at ~150 bytes, which is several hundred GB. That exceeds one comfortable machine, so plan to partition.
- Durability: every mutation is appended to a replicated log (Raft or Paxos group of 3 or 5 nodes) and periodically checkpointed. A new leader replays the latest checkpoint plus log tail.
- Availability: leader election in the consensus group gives failover in seconds. Followers can serve slightly stale reads if the client opts in, reducing leader load.
- Block locations are not persisted. Storage nodes report their blocks via heartbeats and periodic block reports, so the map is rebuilt after a restart. This avoids a consistency problem between two sources of truth.
- Scaling the namespace: partition by directory subtree or by hash of the parent directory ID, each partition being its own consensus group. Cross-partition rename needs a two-phase commit or is restricted. A routing layer maps paths to partitions.
4. Data layer
- Replication: default 3 replicas for hot data. Placement is failure-domain aware: first replica near the writer, second on a different rack, third on another node in that second rack (a common compromise between durability and cross-rack bandwidth).
- Erasure coding (for example Reed-Solomon 6+3) for cold data: about 1.5x storage overhead instead of 3x, tolerates 3 lost fragments, at the cost of more expensive reads during failures and reconstruction. Convert files after they have been cold for some days.
- Integrity: each block stores checksums per small chunk (for example per 64 KB). Verified on read and by a background scrubber. A mismatch marks the replica corrupt and triggers re-replication from a good copy.
5. Read, write and append paths
Read: client asks metadata for the block list and locations (cached with a short TTL), picks the closest replica, streams data, verifies checksums, and falls back to another replica on failure or corruption.
Write:
- Client creates the file; metadata records it and grants a lease to that client.
- For each block, metadata allocates a set of storage nodes.
- Client sends data to the first node, which pipelines it to the second, then the third. Data flow is decoupled from the control flow to use each node's network bandwidth fully.
- Acks flow back. Once all replicas confirm, the client reports block completion; metadata commits it in the log.
- On close, the file becomes visible with its final length.
Append and concurrent writers: one writer holds the lease per file by default, which gives simple, well-defined semantics. If many producers must append to one file, designate a primary replica per block that assigns offsets, so all replicas apply appends in the same order; define the result as at-least-once with record IDs for de-duplication.
Pipeline failure: the client asks metadata for a replacement node, rebuilds the pipeline, and resends unacknowledged data. Uncommitted trailing data is truncated to the last acknowledged length.
6. Failure handling
- Detection: storage nodes send heartbeats every few seconds. After a timeout (for example 10 minutes for permanent failure, shorter for steering reads away), the node is considered dead.
- Re-replication: metadata finds blocks below target replication and schedules copies, prioritizing blocks with the fewest live replicas. Throttle repair traffic so it does not starve clients, and spread the work across many source nodes so recovery of a 20 TB node takes minutes to hours, not days.
- Rack or site loss: failure-domain-aware placement ensures at least one replica survives. A temporary node reboot should not trigger mass copying, which is why the dead-node timeout is generous.
- Metadata node failure: consensus failover as above. Clients retry with backoff and re-resolve the leader. Writes in flight are retried idempotently using request IDs.
7. Operations
- Small files problem: each file costs metadata regardless of size. Mitigations: pack many small files into larger container files (with an index), or store tiny files inline in metadata.
- Rebalancing: a background process moves blocks from over-full to under-full nodes, rate limited, and new nodes are preferred for new blocks.
- Garbage collection: deletes only remove namespace entries (optionally to a trash directory with retention). Storage nodes learn which blocks are orphaned through block reports and delete them lazily. This also cleans up blocks from failed writes.
- Monitoring: under-replicated block count, repair backlog, checksum failure rate, per-node disk usage and latency, metadata RPC latency and leader changes, and namespace memory use.
Trade-offs and common mistakes
- Large blocks reduce metadata load but waste space for small files and limit parallelism for small reads.
- 3x replication is simple and fast to read; erasure coding saves cost but makes repair and degraded reads heavier.
- A single metadata node is simple but is a scale and availability ceiling. Partitioning adds cross-partition operation complexity.
- Common mistakes: skipping requirements, routing data through the metadata service, treating the metadata service as a single point of failure, ignoring rack-level failures, persisting block locations redundantly, and forgetting garbage collection and integrity checking.