Build a Petabyte-Scale Blob Storage Service
System DesignModel answerLast updated
Design a distributed blob storage service with put, get, delete and list, covering metadata, data placement, multipart uploads and the trade-off between replication and erasure coding.
Task
Design a distributed storage service for unstructured files ("blobs") whose sizes range from a few bytes to several terabytes. Users group blobs into named containers and address each blob by a string key.
Operations to support
put(container, key, data): write a blob.get(container, key): read a blob back.delete(container, key): remove a blob.list(container): enumerate the blobs in a container.
Quality goals
- Durability: stored data must survive hardware failures with very high probability.
- Availability: the service keeps working when individual machines fail.
- Scalability: it must hold petabytes of data and sustain heavy request rates.
- Consistency: eventual consistency is acceptable, but explain what that costs and where you would want stronger guarantees.
What to cover
- A high-level architecture that separates the request front end, the metadata layer and the data storage layer.
- How keys are partitioned, and how data is mapped to physical storage nodes.
- How very large blobs are uploaded (multipart or similar).
- How you place data for durability: replication versus erasure coding, and when to use each.
Assumptions you may make
- A distributed coordination store (etcd or ZooKeeper style) is available.
- Each storage node has raw block-level disks.
State your own scale numbers (capacity, object count, request rate, durability target) and justify the design against them.
Hints
Hint 1
Estimate the metadata volume (object count times bytes per record) before choosing where to keep it. Does it fit in a coordination store designed for small data?
Hint 2
Separate two mapping problems: the metadata index (which needs ordered scans for prefix listing) and chunk placement (which needs even spread and control of failure domains).
Hint 3
To avoid readers ever seeing a pointer to missing bytes, decide the order of operations on write: which is made durable first, data or metadata? Then think about what cleans up after a crash.
Hint 4
Compare raw-disk overhead of 3x replication against a Reed-Solomon scheme such as 10+4 at hundreds of petabytes, then ask which data can tolerate the higher read and repair cost.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Scale assumptions
I would fix numbers first, since they drive the design:
- Capacity: about 100 PB logical, growing roughly 30% a year.
- Objects: about 10 billion, with a bimodal size distribution (many under 100 KB, a long tail to 5 TB).
- Traffic: peak of about 100K reads/s and 20K writes/s; reads dominate, and egress bandwidth is a bigger concern than IOPS.
- Targets: eleven nines of durability, 99.99% availability.
- Metadata: 10B objects x ~500 B is about 5 TB.
The metadata figure matters. Coordination stores like etcd or ZooKeeper are built for a few GB of small, strongly consistent data. They should hold cluster membership and the placement map, not per-object metadata. Object metadata goes in a horizontally sharded, consensus-replicated key-value store.
2. API sketch
PUT/GET/DELETE /{container}/{key}, withRangesupport on GET for parallel and resumable downloads.GET /{container}?prefix=&start_after=&limit=returns a page of keys plus a continuation token.- Multipart: initiate (returns
upload_id), upload part N, complete (ordered list of part numbers and checksums), abort.
3. Architecture
- Front end: stateless gateways behind a load balancer that handle authentication, rate limiting and routing.
- Metadata service: sharded, Raft-replicated KV store keyed by
container/key. It stores size, checksum, state (PENDING,COMMITTED,DELETED) and the ordered chunk list. - Data service: storage nodes that append chunks (say 4-64 MB) into large append-only volume files (1-10 GB). Small objects never become individual files, which avoids inode and seek overhead. Each node holds an in-memory index of
(volume, offset)per chunk. - Cluster manager (etcd): membership, health, placement-group map. Background workers do repair, garbage collection and compaction.
Write path: the gateway splits the stream into chunks, asks placement for target nodes, writes all replicas or fragments and waits for durable (fsynced) acks. Only then does it commit the metadata record atomically as COMMITTED. Data first, metadata last means a reader never sees a pointer to missing bytes. A crash leaves orphan chunks that GC reclaims.
Read path: metadata lookup (cached), parallel chunk fetch, checksum verification, stream to client.
4. Partitioning and placement
Metadata: use range partitioning on container/key so a prefix listing is a contiguous scan. Sequential keys such as timestamps create hot ranges, so shards split automatically on size or QPS. Hash partitioning spreads load better but turns every list into a scatter-gather across shards.
Data: compute hash(chunk_id) mod P to pick one of roughly 100K placement groups. The cluster manager maps each group to a set of nodes spread across racks and availability zones, similar to Ceph's CRUSH. Adding nodes moves whole groups, so only about 1/N of data migrates, and rebalancing can be throttled. This gives the benefit of consistent hashing plus explicit failure-domain control.
5. Large blobs: multipart upload
- Initiate creates a pending record and returns an
upload_id. - Upload parts (for example 5 MB to 5 GB each, up to 10,000 parts) independently, in parallel and in any order. Each part is chunked and stored like a normal object, and its checksum is recorded under the upload.
- Complete: the client sends the ordered
(part, checksum)list. The metadata service validates it and writes the final chunk list in one atomic transaction. No bytes are copied; the blob is a concatenation of pointers. - Abort or a lifecycle TTL marks the parts for GC.
Benefits: blobs can exceed any node's capacity, throughput scales with client parallelism, and a failure costs one part rather than the whole upload.
6. Replication vs. erasure coding
| 3x replication | Reed-Solomon (10,4) | |
|---|---|---|
| Raw overhead | 3.0x | 1.4x |
| Tolerates | 2 lost copies | any 4 lost fragments |
| Read cost | 1 node | up to 10 nodes (1 if the data fragment is intact) |
| Repair cost | copy one chunk | read 10 fragments to rebuild 1 |
| Best for | small, hot, fresh data | large, cold, sealed data |
At 100 PB, coding saves roughly 160 PB of raw disk, which is the deciding argument. The usual answer is a hybrid: write new data with 3x replication for low latency and simple appends; when a volume fills it is sealed, then a background job erasure-codes it across failure domains and drops the replicas. Refinements: locally repairable codes to cut repair bandwidth, and cross-AZ coding to survive losing a whole zone.
Durability is more than the code choice:
- Checksums on every chunk.
- A background scrubber verifying data at rest.
- Fast repair, since mean time to repair matters as much as copy count.
7. Consistency trade-offs
With eventual consistency we can replicate metadata asynchronously across regions, serve reads from followers and caches, and update list indexes lazily. The price: a read after an overwrite may return the old version, and a list right after a put may miss the key. Because chunks are immutable, a stale reader sees an old but complete version, never a torn one. If strong read-after-write is required, route reads through the shard leader (or use a read index) and make list indexes transactional with the commit, at the cost of latency and leader load.
8. Common mistakes
- Putting per-object metadata in etcd or ZooKeeper.
- Storing each small object as its own file.
- Committing metadata before data is durable.
- Hash-partitioning metadata and then promising cheap prefix listing.
- Choosing erasure coding everywhere and ignoring read and repair amplification for small, hot objects.
- Forgetting garbage collection for orphaned chunks, aborted uploads and deleted objects.
- Describing replication without failure domains (rack, AZ).