Design Object Storage

How to design an object store such as S3: metadata versus data, replication versus erasure coding, multipart upload, listing and garbage collection.

Case study27 minLesson 6 of 7
On this page
  1. Clarify the problem
  2. Estimate the scale
  3. Define the API (optional)
  4. Model the data
  5. High-level design
  6. Deep dives
  7. Bottlenecks and failures
  8. What a strong answer sounds like
  9. Follow-up questions

An object store keeps immutable blobs of any size, from empty to a terabyte, under a bucket and a key, and returns them later by that key. Amazon S3 is the best-known example. Many other designs in this track simply say "the bytes go in an object store", and this case study designs that component itself. The client-side view is in Blob Storage, and the steps here follow A Framework for Any Design.

The design is hard because durability must hold across many disk failures over many years, yet at hundreds of petabytes the extra copies are the largest cost, and the index of billions of keys must be strongly consistent and listable by prefix.

Clarify the problem

The first five minutes
Interviewer

Design an object storage service.

You

I will assume buckets that hold objects addressed by key, with put, get, delete and list by prefix. Objects are replaced as a whole and never edited in place. How large can one object be, and do we need versioning?

Interviewer

Objects range from zero bytes up to 1 TB. Versioning is a stretch goal.

You

How much data is there, and how busy is it?

Interviewer

Assume 100 PB in about 100 billion objects, growing by 10 PB a month, with about 4,000 writes and 40,000 reads a second.

You

Then I will put durability first, because a lost object can never be recovered. Read availability comes second. Cost per byte comes third, because at 100 PB the storage overhead is most of the bill.

The requirements we will design for are these.

  • Functional: create buckets; put, get (the whole object or a byte range) and delete objects; list keys by prefix in pages; upload large objects in parts.
  • Non-functional: a durability of eleven nines per object per year; read availability of 99.99%; a successful put is visible to every later get and list; the first byte of a read arrives within about 100 ms; storage overhead well below 3x.
  • Out of scope: access policies, billing, storage classes and cross-region replication. Versioning is covered in the follow-ups.

Estimate the scale

The average object is 100 PB ÷ 100 billion = 1 MB. Ingest is 4,000 puts a second × 1 MB = 4 GB/s, which over a month of about 2.6 million seconds is roughly 10 billion objects and 10 PB, matching the stated growth. Egress is 40,000 gets a second × 1 MB = 40 GB/s, or 120 GB/s at a peak of three times the average. At about 1 GB/s per front-end server that is around 120 front ends, so network bandwidth limits the front-end tier.

Estimate: Metadata size

Each object has a metadata row holding its bucket, key, size, checksum and the location of its bytes. How much metadata is there, before replication?

You know
  • 100 billion objects
  • About 500 bytes per metadata row

Show the working
  1. 100 × 109 × 500 B = 5 × 1013 B = 50 TB
  2. With 3 replicas this is 150 TB

Estimate 50 TB (anything from 15 TB to 150 TB is a good answer)

This is far too much for one machine, so the metadata store has to be sharded, and every request touches it.

Raw disk depends on the durability scheme: three full copies of 100 PB need 300 PB, while erasure coding with 10 data and 4 parity fragments needs 100 PB × 14 ÷ 10 = 140 PB.

Your turn: Define the API

Write the calls for put, get, delete, list and multipart upload. How does the client know that its bytes arrived intact?

Compare with a model answer

Put, get and delete work on /{bucket}/{key}, list takes a prefix and a page token, and multipart upload has start, part and complete calls. The put carries a checksum, and the server refuses the object if the bytes do not match it.

Define the API Optional

Optional in the interview. Sketch the API only if the interviewer asks, if an API choice shapes the design, or if time permits. Otherwise say "I'll skip the detailed API unless you want it" and go to the data model.

HTTP API
PUT    /{bucket}/{key}          x-checksum: sha256=9f2c...
  200 { "etag": "9f2c...", "version": "v2" }
  400 Bad Digest            bytes do not match the checksum; nothing stored
  412 Precondition Failed   If-Match / If-None-Match did not hold
 
GET    /{bucket}/{key}          Range: bytes=0-1048575 (optional)
  200 or 206 + bytes         404 no such key
 
DELETE /{bucket}/{key}
  204 No Content             also when the key did not exist
 
GET    /{bucket}?prefix=photos/2026/&delimiter=/&limit=1000&after=...
  200 { "keys": [...], "prefixes": ["photos/2026/01/"], "next": "token" }
 
POST   /{bucket}/{key}?uploads                start  -> { "upload_id": "u7" }
PUT    /{bucket}/{key}?upload_id=u7&part=3   one part -> { "etag": "..." }
POST   /{bucket}/{key}?upload_id=u7          complete, body: [{part, etag}, ...]
DELETE /{bucket}/{key}?upload_id=u7          abort

The API decision worth arguing is two clients putting the same key at once. The last writer wins, decided by the order of the metadata commits. A client that needs more control sends a conditional put: If-None-Match: * stores only if the key does not exist, and If-Match: <etag> stores only if the object is unchanged since it was read. This is compare-and-swap without locks. Delete returns 204 even for a missing key, so retries are safe (see idempotency and retries).

Your turn: Model the data

Which records describe an object, and where do its bytes live? What has to change when a failed disk is rebuilt on another machine?

Compare with a model answer

An object row maps a key to chunks inside large volumes, and a separate volume map says which disks hold each volume. A rebuild only changes the volume map and never the billions of object rows.

Model the data

Metadata
objects                       -- sorted by (bucket_id, key)
  bucket_id    BIGINT
  key          VARCHAR(1024)  -- "photos/2026/cat.jpg"
  version      BIGINT
  size_bytes   BIGINT
  checksum     CHAR(64)       -- sha256 of the bytes (multipart: of the parts' sums)
  chunks       LIST           -- [(volume_id, chunk_id, length, crc32c), ...]
  PRIMARY KEY (bucket_id, key)
 
volumes                       -- the volume map, about 10 million rows
  volume_id    BIGINT PRIMARY KEY
  state        VARCHAR(8)     -- open | sealed | coded
  layout       LIST           -- 3 disks while open; 14 fragment disks once coded
  generation   INT            -- bumped when compaction rewrites it
 
multipart_parts
  upload_id, part_number, chunks, checksum

The lookup has three hops: the key leads to its chunks, each chunk belongs to a volume, and the volume map says which disks hold it. A volume is an append-only file of about 10 GB holding chunks of many objects, so 100 PB means 10 million volumes and a volume map of about 2 GB at 200 bytes a row, small enough for every front end to cache.

Gets and puts are strongly consistent lookups of a single key, and list scans keys in sorted order starting from a prefix. Sorted order rules out hash partitioning, because hashing scatters neighbouring keys across shards. The right category is a range-partitioned, sorted key-value store, such as TiKV. Each key range is replicated three ways using consensus, and a range that becomes busy or large is split in two.

Your turn: High-level design

Sketch the boxes. Which component chooses the disks, which step makes an object visible, and what runs in the background?

Compare with a model answer

The boxes are front ends, a metadata service, a placement service, storage nodes, and background workers for scrubbing, repair, coding and garbage collection. The object exists from the moment its metadata row is committed.

High-level design

Metadata is small, strongly consistent and touched by every request, while data is huge, written once and mostly cold, so they are separate services. A put writes the bytes first and the metadata second, so a row never points at missing bytes.

Bytes go to storage nodes chosen by the placement service, and the object exists only once the metadata service commits its row.Client to Front-end API (PUT / GET); Front-end API to Metadata service (key → chunks); Front-end API to Placement service (which volume); Front-end API to Storage nodes (chunk bytes); Metadata service to Sorted metadata store; Storage nodes to Placement service (heartbeats), asynchronous; Scrub, repair, GC to Storage nodes (verify, rebuild); Scrub, repair, GC to Sorted metadata store (live chunks).ClientFront-end APIMetadata servicePlacementserviceStorage nodesSorted metadatastoreScrub, repair,GCPUT / GETkey → chunkswhich volumechunk bytesheartbeatsverify, rebuildlive chunks

request and replyasynchronous message

Bytes go to storage nodes chosen by the placement service, and the object exists only once the metadata service commits its row.
A put, a get, bit rot, and a crash before commitUse the arrows or ← → keys
  1. A put, a get, bit rot, and a crash before commit, step 1Client to Front-end API; Front-end API to Metadata service; Front-end API to Placement service; Front-end API to Storage nodes; Metadata service to Sorted metadata store; Storage nodes to Placement service, asynchronous; Scrub, repair, GC to Storage nodes; Scrub, repair, GC to Sorted metadata store.ClientFront-end APIMetadata servicePlacementserviceStorage nodesSorted metadatastoreScrub, repair,GC
    object
    4 MB
    visible
    no

    1A client sends PUT photos/2026/cat.jpg with 4 MB of data and its SHA-256. Any front end can accept the request.

  2. A put, a get, bit rot, and a crash before commit, step 2Client to Front-end API; Front-end API to Metadata service; Front-end API to Placement service; Front-end API to Storage nodes; Metadata service to Sorted metadata store; Storage nodes to Placement service, asynchronous; Scrub, repair, GC to Storage nodes; Scrub, repair, GC to Sorted metadata store.ClientFront-end APIMetadata servicePlacementservicevol 5,120,331Storage nodesSorted metadatastoreScrub, repair,GC
    object
    4 MB
    visible
    no

    2The placement service gives the front end an open volume, number 5,120,331, which lives on three nodes in three different racks.

  3. A put, a get, bit rot, and a crash before commit, step 3Client to Front-end API; Front-end API to Metadata service; Front-end API to Placement service; Front-end API to Storage nodes; Metadata service to Sorted metadata store; Storage nodes to Placement service, asynchronous; Scrub, repair, GC to Storage nodes; Scrub, repair, GC to Sorted metadata store.ClientFront-end APIMetadata servicePlacementserviceStorage nodes3 of 3 syncedSorted metadatastoreScrub, repair,GC
    object
    4 MB
    copies on disk
    3
    visible
    no

    3The 4 MB streams to all three nodes. Each node appends the data, verifies the checksum and flushes it to disk before it answers.

  4. A put, a get, bit rot, and a crash before commit, step 4Client to Front-end API; Front-end API to Metadata service; Front-end API to Placement service; Front-end API to Storage nodes; Metadata service to Sorted metadata store; Storage nodes to Placement service, asynchronous; Scrub, repair, GC to Storage nodes; Scrub, repair, GC to Sorted metadata store.ClientFront-end APIMetadata servicePlacementserviceStorage nodesSorted metadatastorecat.jpg v2Scrub, repair,GC
    object
    4 MB
    copies on disk
    3
    visible
    yes

    4This is the commit point. The metadata service writes the key's row through the consensus group of its range, and from then on every get and list sees the object.

  5. A put, a get, bit rot, and a crash before commit, step 5Client to Front-end API; Front-end API to Metadata service; Front-end API to Placement service; Front-end API to Storage nodes; Metadata service to Sorted metadata store; Storage nodes to Placement service, asynchronous; Scrub, repair, GC to Storage nodes; Scrub, repair, GC to Sorted metadata store.ClientFront-end APIMetadata servicevol 5,120,331PlacementserviceStorage nodesSorted metadatastoreScrub, repair,GC
    copies on disk
    3

    5Later, a client reads the object. A key lookup in the metadata store returns the chunk and its volume, and the volume map cached in the front end gives the disks.

  6. A put, a get, bit rot, and a crash before commit, step 6Client to Front-end API; Front-end API to Metadata service; Front-end API to Placement service; Front-end API to Storage nodes; Metadata service to Sorted metadata store; Storage nodes to Placement service, asynchronous; Scrub, repair, GC to Storage nodes; Scrub, repair, GC to Sorted metadata store.ClientFront-end APIMetadata servicePlacementserviceStorage nodesCRC mismatchSorted metadatastoreScrub, repair,GCrepair copy 1
    good copies
    2

    6The first copy fails its CRC check, so the front end reads the second copy and streams it to the client. A repair worker then rewrites the damaged copy.

  7. A put, a get, bit rot, and a crash before commit, step 7Client to Front-end API; Front-end API to Metadata service; Front-end API to Placement service; Front-end API to Storage nodes; Metadata service to Sorted metadata store; Storage nodes to Placement service, asynchronous; Scrub, repair, GC to Storage nodes; Scrub, repair, GC to Sorted metadata store.ClientFront-end APIdownMetadata servicePlacementserviceStorage nodes4 MB orphanSorted metadatastoreScrub, repair,GC
    orphaned bytes
    4 MB
    visible
    old version

    7Now a different put. Its bytes reach all three nodes, and then the front end crashes before it writes the metadata row. The client retries, and the old version of the object is untouched.

  8. A put, a get, bit rot, and a crash before commit, step 8Client to Front-end API; Front-end API to Metadata service; Front-end API to Placement service; Front-end API to Storage nodes; Metadata service to Sorted metadata store; Storage nodes to Placement service, asynchronous; Scrub, repair, GC to Storage nodes; Scrub, repair, GC to Sorted metadata store.ClientFront-end APIMetadata servicePlacementserviceStorage nodesSorted metadatastoreScrub, repair,GC
    orphaned bytes
    0

    8No metadata row points at those 4 MB. The garbage collector waits out a grace period in case a commit is still in flight, and then reclaims the space.

1 / 8

Deep dives

Durability: full copies or erasure coding

Eleven nines means a 1 in 1011 yearly chance of losing a given object, about one object a year at 100 billion objects. To compare the schemes, assume 2% of disks fail each year and a lost piece is rebuilt within 24 hours, so a given disk fails inside one repair window with probability p = 0.02 × 24 ÷ 8,760 ≈ 5.5 × 10−5.

Three full copies. Each copy is on a different disk and any copy serves a read, so repair is a plain copy. One of the 3 disks fails 3 × 0.02 = 0.06 times a year, and the object is lost only if both others fail before the rebuild, with probability p² ≈ 3.0 × 10−9. The yearly loss is about 0.06 × 3.0 × 10−9 = 1.8 × 10−10, just under ten nines or about 18 objects a year, for 300 PB of disk.

Erasure coding with 10 data and 4 parity fragments. The object is cut into 10 data fragments and 4 parity fragments are computed from them; any 10 of the 14 rebuild it. One of the 14 disks fails 14 × 0.02 = 0.28 times a year, and the object is lost only if 4 of the other 13 fail before the rebuild, with probability 715 × p⁴ ≈ 6.4 × 10−15. The yearly loss is about 0.28 × 6.4 × 10−15 ≈ 1.8 × 10−15, almost fifteen nines, for 140 PB.

The cost of coding is repair work. Rebuilding one fragment reads 10 others, so rebuilding a 20 TB disk reads 200 TB, about 2.3 GB/s over 24 hours, against 0.23 GB/s for copies. Normal reads are unaffected, because the 10 data fragments hold the original bytes.

Coding needs a whole volume, so new data goes to an open volume as three full copies, and a sealed volume is later encoded into 14 fragments in the background.

How to survive disk failures
OptionGood atBad atPick it when
3 full copiesAny copy serves a read, and a rebuild reads only the data that was lost.It needs 3x the disk, 300 PB for 100 PB of data, and gives about ten nines with a day-long repair.Use it for open volumes that are still receiving writes.
Erasure coding 10 + 4It needs 1.4x the disk, 140 PB, and survives the loss of any 4 fragments.Rebuilding one fragment reads 10 fragments, and so does a read while some fragments are unavailable.Use it for sealed volumes of large, mostly cold data, which is most of the store.
Copies first, then code Usual defaultPuts are fast appends to 3 replicas, and sealed volumes are coded in the background.The coding traffic is about as large as the ingest traffic, and two layouts have to be operated.Use it when you need both fast writes and cheap storage. This is our design.

Both calculations assume independent failures, but real failures are correlated: a rack loses power or a release deletes the wrong files. The defences are rack-aware placement, gradual rollouts and several days of delay before erasing deleted data. A silently corrupted copy counts as missing, so every read checks a CRC and a scrubber rereads every disk.

Large objects and multipart upload

Streaming 1 TB in one request is fragile, since any network error means starting over. Multipart upload lets the client send numbered parts, such as 10,000 parts of 100 MB, in parallel and retry each separately. Each part is stored like a small object.

Completing the upload moves no bytes. The service checks every listed part and its etag, then writes one object row that lists the parts' chunks in order, in a single transaction, so a 1 TB object appears atomically within milliseconds. Aborted and long-idle uploads have their part rows deleted and their chunks left to garbage collection.

Listing keys by prefix

An object store has no real folders. A key such as photos/2026/cat.jpg is one string, and listing photos/2026/ is a range scan over the sorted metadata store, starting at the prefix and stopping at the first key that no longer matches. A listing returns at most 1,000 keys plus a token that holds the last key returned, and the next call continues from that key.

With delimiter=/, keys under photos/2026/01/ come back as one entry in prefixes, and the scan skips past that prefix.

Keys that start with a timestamp all land at the end of one range, and splitting it does not help, so a short hash prefix is used to spread writes, at the price that a listing by time must scan several prefixes. List reads the same consistent store as get, so a key is listed as soon as its put returns.

Deleting objects and reclaiming space

A delete removes the object row immediately, but the bytes stay in the volume. Volumes are append-only, so the system must find unreferenced chunks and rewrite volumes that are mostly garbage. There are two ways to find them.

Reference counting keeps a counter of dead bytes for each volume and updates it on every delete. It shows right away which volumes are mostly garbage and are worth compacting. Its weakness is that a lost update leaks space, an extra update can mark live data as dead, and it never learns about the orphan bytes left by a put that crashed before committing.

Mark and sweep scans every object row, collects the set of chunk ids that are live, and treats every other chunk as garbage, including the orphans of crashed puts. It is accurate, but scanning 50 TB of metadata takes hours, so garbage waits days before it is found.

The design uses both, with two safety rules. A chunk is never erased until it is a few days old, because its put may not have committed, and the commit refuses chunks older than a day. Compaction keeps chunk ids: when a sealed volume is over 40% dead, a worker copies its live chunks into a new generation of the volume and updates the volume map, so object rows need no change. Erasing bytes at delete time is tempting but wrong, because it races with puts and compaction and lets one bug destroy data instantly.

Bottlenecks and failures

What breaks first at 10x

At ten times the load, 40,000 puts and 400,000 gets a second, storage nodes and front ends scale by adding machines, and new volumes go to the emptiest disks so nothing old moves. The metadata store strains first, because every put is a consensus write. Split busy ranges and cache hot rows in the front ends.

What happens when each component fails

  • A front end. In-flight requests fail, and an interrupted put leaves orphan bytes but never a half-written object, because the row is committed last. Clients retry and garbage collection reclaims the orphans.
  • A metadata range leader. That range pauses for a few seconds while a new leader is elected. No committed row is lost, because a majority had it before the acknowledgement.
  • The placement service. No new volumes are handed out, but front ends keep writing to their open volumes and reading with the cached volume map.
  • A disk, a node or a rack. Reads use another copy or decode from any 10 of 14 fragments, and repair rebuilds the lost pieces within hours. Each volume has at most one piece per rack, so a rack failure costs each volume one piece.

What a strong answer sounds like

LevelWhat the answer does
JuniorStores files on servers, keeps a database of names, and makes 3 copies without saying how many failures that survives.
MidSeparates metadata from data, compares replication and erasure coding by their storage overhead, and covers multipart upload and checksums.
SeniorDerives durability from stated assumptions, prices the repair traffic of erasure coding, makes the metadata commit the point where an object becomes visible, chooses a sorted store for listing, and delays the erasure of deleted data.
Defending durabilityStrong answer
Interviewer

How durable is your design?

You

If 2% of disks fail each year and a lost piece is rebuilt within a day, three copies lose about 2 objects in 10 billion a year, just short of ten nines. Erasure coding with 10 data and 4 parity fragments reaches almost fifteen nines at 1.4x the space. That assumes independent failures, so the real risks are correlated ones such as a rack losing power or a bug in our own software.

Follow-up questions

How would you add versioning?

Make the version part of the metadata key, so each put adds a row and a delete adds a "delete marker" row. A plain get returns the newest row that is not a marker. Garbage collection must treat every version's chunks as live, so a lifecycle rule is needed to expire old versions.

How do you survive losing a whole data center?

Place fragments so that no zone holds more than the code can lose. With 3 zones and 12 data plus 6 parity fragments, each zone holds 6, and losing a zone still leaves the 12 needed. The overhead is 18 ÷ 12 = 1.5x. While a zone is down there is no spare margin, so repair must start immediately.

One object gets 50,000 reads a second. What breaks?

The few disks holding it are overloaded. Cache hot objects in the front ends or a CDN; objects never change in place, so an entry can only be stale until its time to live ends.

What goes wrong with millions of tiny objects?

The object data is small but every object still needs one metadata row of about 500 bytes, so metadata can outgrow the data and the metadata store becomes the cost and the bottleneck.

Self-review: object storage0 of 13

After your attempt, tick what you really did. Be strict: "I thought about it" is not "I said it out loud".

Before drawing

Numbers and interfaces

Design and depth

Failure