InterviewDryRun
Lesson 27 · 24 min video · free

Design Object Storage

Object storage keeps any number of files, from a few bytes to terabytes, behind a simple put, get, list and delete API, and almost never loses one. This lesson designs it: a stateless front end, a metadata service that maps bucket and key to where the bytes live, storage nodes that hold the bytes with erasure coding across failure domains, multipart uploads for huge files, versioning, and background repair that keeps durability at eleven nines.

What you will learn

  • Separate metadata (bucket, key, version, location) from data (the bytes); they scale and fail differently.
  • Objects are immutable: a new upload writes new bytes and then switches the metadata pointer.
  • Erasure coding gives the durability of many copies at about 1.5 times the space, spread across failure domains.
  • Pack small objects into large files on disk; one file per object wastes disks and memory.
  • Large files use multipart uploads: parts upload in parallel, retry alone, and commit atomically.
  • Durability is kept by constant background work: checksums, scrubbing and fast repair after failures.

In this lesson

  1. The question
  2. Step 1: Clarify the requirements
  3. Step 2: Back-of-the-envelope estimates
  4. Step 3: The API
  5. Step 4: Separating metadata from data
  6. Step 5: Replication or erasure coding
  7. Step 6: Where eleven nines comes from
  8. Step 7: Storing small objects efficiently
  9. Step 8: The metadata store and listing
  10. Step 9: Large uploads
  11. Step 10: Versioning
  12. Step 11: Deletes and garbage collection
  13. Step 12: One upload, end to end
  14. Step 13: Scaling and failures
  15. Step 14: The parts people forget
  16. Step 15: The follow-up questions
  17. Recap
Practice this question with Max

The question

Welcome to lesson twenty-seven of the InterviewDryRun system design course. Today we design object storage: a service that stores files, called objects, in containers called buckets, and gives them back on request, at any scale, for years, without losing them.

Object storage is the quiet foundation under much of the internet. Photos, video files, backups, logs, data lakes and machine learning datasets all live in it. Its API is tiny: put an object, get it, list them, delete one. All the difficulty is underneath: storing exabytes on disks that fail every day, and still promising that an object, once stored, is essentially never lost. This question tests storage fundamentals: durability, metadata at scale, and the trade-off between copies and cost.

Max asks

“Design an object store with buckets, large uploads, durability and versioning.”

That is how Max, our AI interviewer, asks it. Four topics are named: buckets, large uploads, durability and versioning. Buckets means a namespace and access control. Large uploads means files of many gigabytes, which cannot be sent in one request. Durability is the heart of the question. And versioning means keeping old versions of an object when it is overwritten or deleted.

The plan: requirements and numbers, then the API. Then the key architectural decision, separating metadata from data. Then how bytes are placed and protected, with replication and erasure coding, how small objects are stored efficiently, the metadata store and listing, multipart uploads, versioning, garbage collection, repair, one upload walked end to end, and the follow-up questions.

Step 1: Clarify the requirements

Functional requirements
  1. 01
    BucketsCreate, delete, set access rules
  2. 02
    ObjectsPut, get (whole or a byte range), delete, head
  3. 03
    ListKeys in a bucket by prefix, page by page
  4. 04
    Large uploadsMultipart: many parts, then complete
  5. 05
    VersioningKeep every version; restore old ones

Start with questions.

Users create buckets, which have globally unique names and access rules. Inside a bucket, objects are addressed by a key, any string, like photos slash twenty twenty-six slash beach dot jpeg. There are no real folders; the slashes are just characters, but listing by prefix makes them feel like folders.

Users put, get and delete objects, and can get a byte range, which video players use to seek. They list keys under a prefix, in pages. Large files are uploaded in parts, and with versioning on, every overwrite or delete keeps the previous version.

Ask about the size range: from a few bytes to, say, five terabytes per object. And about updates: can you modify part of an object? In object storage, no. Objects are immutable; you replace the whole thing. That rule simplifies almost everything, and you should say so.

Non-functional requirements
  1. 01
    DurabilityEleven nines: lose 1 in 100 billion objects a year
  2. 02
    AvailabilityFour nines for reads
  3. 03
    Strong consistencyA read after a write sees the write
  4. 04
    ScaleExabytes, trillions of objects
  5. 05
    CostCheap per gigabyte; storage dominates

The qualities.

Durability is the headline: eleven nines, meaning if you store a hundred billion objects, you expect to lose about one a year. Availability can be lower, four nines: an object briefly unreachable is acceptable, an object lost is not. Separate those two words clearly, because candidates often mix them up.

Consistency: after a successful put, a get or a list should see the new object. Modern object stores promise that, and it affects the metadata design. And scale and cost: exabytes of data means the cost per gigabyte of raw disk decides whether the business works, which is why the durability technique matters so much.

Step 2: Back-of-the-envelope estimates

Sizing it
Data stored1 exabyteone million terabytes
Objects1 trillionaverage 1 MB; median far smaller
Metadata per objectabout 1 KBso about 1 PB of metadata
Disksabout 100,00020 TB each, before redundancy
Disk failuresdozens a dayat 2% a year per disk

Let us size it.

Say one exabyte of data, a million terabytes, in one trillion objects. The average is one megabyte, but the distribution is skewed: most objects are small, a few kilobytes, and a small number of huge ones hold most of the bytes.

Metadata, the key, size, checksum, version and location, is about a kilobyte per object, so a petabyte of metadata in total. That is far too much for one database. Metadata needs its own distributed design.

On twenty terabyte disks, one exabyte needs fifty thousand disks just for the data, and around a hundred thousand once we add redundancy. At a typical failure rate of two percent a year, that is two thousand failed disks a year, more than five a day, and in practice dozens of components a day if you count servers and network.

This last number is the one to dwell on. At this scale, failure is not an event, it is the weather. The design must treat disk loss as routine background work, not as an incident. That idea sets up the whole durability discussion.

Step 3: The API

API
PUT    /{bucket}                               create bucket
PUT    /{bucket}/{key}          body           → ETag, versionId
GET    /{bucket}/{key}?versionId=…  Range: bytes=0-1048575
HEAD   /{bucket}/{key}                         metadata only
DELETE /{bucket}/{key}                         → delete marker if versioned
GET    /{bucket}?prefix=photos/&delimiter=/&continuation=…

POST   /{bucket}/{key}?uploads                 → uploadId
PUT    /{bucket}/{key}?uploadId=…&part=7       → part ETag
POST   /{bucket}/{key}?uploadId=…  [parts]     complete

The API is small, and that is a feature.

Put stores an object and returns an entity tag, a checksum-based fingerprint, and a version id if versioning is on. Get returns it, optionally a byte range, optionally an older version. Head returns only the metadata. Delete removes it, or, with versioning, adds a delete marker, which we will explain.

List returns keys under a prefix, in sorted order, a page at a time, with a continuation token. A delimiter, usually a slash, groups keys into common prefixes, which is how a console shows folders that do not really exist.

And multipart upload is three calls: start an upload and get an upload id; upload numbered parts, independently and in any order; then complete, listing the parts. Requests are authenticated with signatures over the request, and the same mechanism produces pre-signed links that let a browser upload or download one object directly, for a limited time, without credentials.

Step 4: Separating metadata from data

The architecture
lookupbytesCLIENTClientsSERVICEFront endauth, routingSTOREMetadata servicebucket, key → locationSERVICEPlacement servicecluster mapSTOREStorage nodesbytes on disksWORKERBackgroundrepair, GC, scrub

The key architectural decision: keep metadata and data in separate systems.

Clients talk to a stateless front end, which authenticates the request, checks the bucket's access rules, and coordinates the operation. It holds no data, so it scales by adding servers.

The metadata service maps a bucket and key, and a version, to everything about the object: size, checksum, content type, owner, and, crucially, where its bytes are stored. It is a large, sharded, strongly consistent key-value store.

The storage nodes hold the bytes, on many disks, and know nothing about buckets or keys. They store chunks identified by ids, and answer, give me chunk such and such. The placement service keeps the map of the cluster: which nodes and disks exist, in which racks and zones, and which are healthy, and decides where new chunks go.

Why separate them? Their shapes are opposite. Metadata is small per object, queried often, must support listing and strong consistency, and fits on fast flash storage. Data is huge, written once, read in large sequential streams, and lives on cheap high-capacity disks. One system optimised for both would do both badly. And because objects are immutable, the link between them is simple: the bytes are written first, and only then does the metadata point at them.

Background workers do the constant maintenance: repairing lost chunks, reclaiming space from deleted objects, and checking stored data for silent corruption. They are half of the system's real work.

Step 5: Replication or erasure coding

Protecting the bytes
SchemeSpace usedSurvivesNotes
3 copies3×loss of any 2simple; fast reads and repair; expensive
Erasure code 6+31.5×loss of any 3half the cost of 3 copies
Erasure code 8+41.5×loss of any 4wider; more parallel reads
Across 3 zones~1.8× with local paritya whole zonefor zone-level durability

Now the heart of the question. How do we make the bytes survive disk, server, rack and even data centre failures?

The simple answer is replication: store three copies on three different servers, in different racks or zones. Any two can fail and the object survives. Reads are fast, repair is a simple copy. But three times the disks for an exabyte is two extra exabytes of disks, an enormous cost.

Erasure coding does better. Split an object's data into, say, six data fragments, and compute three parity fragments from them using mathematics similar to what makes damaged discs readable. Store the nine fragments on nine different servers. Any six of the nine are enough to rebuild the object, so we survive the loss of any three, better than three-way replication, while using only one and a half times the space.

Wider codes, like eight data and four parity fragments, survive four losses at the same overhead and spread reads over more disks. The price of erasure coding is compute to encode and decode, more network traffic to repair a fragment, since rebuilding one fragment means reading six others, and slightly slower small reads.

Fragments must land in different failure domains: different disks, servers and racks, and for the highest durability, different zones. Spreading nine fragments across three zones, three per zone, means losing a whole zone loses three fragments, which we can tolerate.

A practical design uses both: new, hot or small objects are stored with replication for speed, and data is erasure coded as it cools or as chunks fill up. Saying that, with the one and a half versus three numbers, is exactly what an interviewer is looking for in this step.

Step 6: Where eleven nines comes from

Durability is a race
  1. 01
    FailuresDisks fail at random, a few a day per cluster
  2. 02
    RepairLost fragments rebuilt from the others
  3. 03
    Risk windowData is at risk only until repair finishes
  4. 04
    Fast repairSpread rebuild over many disks: minutes, not days
  5. 05
    Silent corruptionChecksums and scrubbing catch bad bits

Eleven nines sounds like a marketing number, but you can reason about it.

Data is lost only if more fragments of the same object fail than the code can tolerate, before any of them are repaired. With six plus three, four fragments of one object would have to be lost within one repair window.

So durability is a race between failure and repair. If repairing a failed disk takes a day, the window is a day. If it takes an hour, the chance of extra failures in that window drops roughly in proportion, and with several failures needed, the overall probability falls very sharply.

How do we repair a twenty terabyte disk in an hour? Not by copying it to one new disk, which takes a day at disk speed. The fragments on the failed disk belong to millions of different objects, whose other fragments are spread across thousands of disks. So thousands of disks each rebuild a small share in parallel, writing the new fragments to many different disks. Spreading data widely makes repair fast, and fast repair is what produces the nines.

And the failures you do not see: a bit flips on a disk, or firmware writes the wrong block. Every chunk is stored with a checksum, checked on every read, and a background scrubber reads every chunk every few weeks to find silent corruption before a second failure makes it unrecoverable. Name scrubbing; many candidates forget that disks can lie.

Step 7: Storing small objects efficiently

Small objects
  1. 01
    One file per objectBillions of files; metadata overload; seeks
  2. 02
    Pack into large chunksAppend objects into 256 MB chunk files
  3. 03
    Locate by offsetMetadata: chunk id, offset, length
  4. 04
    Code the chunkErasure code whole chunks once sealed

Most objects are small, a few kilobytes. Storing each one as a separate file on a disk's file system is a classic mistake.

A file system with billions of tiny files spends more on its own bookkeeping than on the data. Each file needs an index entry, often a disk seek to open, and wastes the rest of its last block. Reading one small object can take several disk seeks, which is slow on spinning disks.

Instead, storage nodes append objects into large chunk files, say two hundred and fifty-six megabytes each. An object's location in the metadata becomes a chunk id, an offset and a length. Reading it is one seek and one read. Writing is a sequential append, which disks love.

When a chunk fills up, it is sealed: it never changes again. A sealed chunk is then erasure coded as a unit, into fragments spread across servers. Coding whole chunks, rather than each tiny object, avoids the overhead of splitting a two kilobyte object into nine pieces. Large objects, on the other hand, are split across many chunks, so a terabyte file is spread across thousands of disks and can be read in parallel.

Step 8: The metadata store and listing

A metadata record
key:    (bucket, objectKey, version)     sorted
value:  { size, etag, contentType, created, owner,
          storageClass, chunks: [ (chunkId, offset, length) ], 
          isDeleteMarker }

partition: by range of (bucket, objectKey)
split hot or large ranges automatically

Now metadata: a trillion entries, a petabyte, strongly consistent, and it must support listing keys in order by prefix.

Each record is keyed by bucket, object key and version, and holds the object's attributes and the list of chunk locations. Because listing must return keys in sorted order by prefix, we partition by ranges of the key, not by a hash. A hash would scatter photos slash a and photos slash b across every partition, and listing would have to ask all of them.

Range partitioning has a known problem: hot spots. If a customer writes keys that all start with today's date, every write lands on the same range. The fix is automatic splitting: when a range grows too large or too busy, split it in two and move one half to another server. Some systems also advise customers to add a random prefix for extreme write rates, but automatic splitting handles most cases.

Each range is replicated, typically three times across zones, with a consensus protocol, so it stays consistent and available when a server fails. That gives strong consistency: once a put's metadata is committed, any read or list goes to the range's leader, or a replica that is known to be up to date, and sees it.

Listing a prefix is then a range scan: start at the prefix, read keys in order, return a page of a thousand, and hand back the last key as the continuation token. With a delimiter, the scan groups keys into common prefixes as it goes. It is efficient precisely because of the sorted, range-partitioned design.

Step 9: Large uploads

Multipart upload
  1. 01
    InitiateGet an upload id
  2. 02
    Upload parts5 MB to 5 GB each, in parallel, retry alone
  3. 03
    Each part storedLike a small object, with its own checksum
  4. 04
    CompleteList of part numbers and ETags; commit atomically
  5. 05
    Abort or expireUnfinished uploads cleaned up after days

A five hundred gigabyte file cannot be sent in one request. A dropped connection at ninety percent would mean starting over, and one stream is limited by one connection's speed.

Multipart upload solves both. The client initiates an upload and receives an id. It then splits the file into numbered parts, uploads them in parallel over several connections, and retries any part that fails, by itself.

Each part is stored like an object of its own, in chunks, with a checksum, but it is not visible in the bucket yet. The metadata service records each part against the upload id.

When all parts are uploaded, the client calls complete with the list of part numbers and their tags. The service checks every part exists and matches, then, in one metadata transaction, creates the object record whose chunk list is the parts in order. No bytes are copied: the object simply points at the parts' chunks. Until that commit, readers see the old version or nothing; afterwards they see the whole new object. That atomic switch is what makes large uploads safe.

Uploads that are never completed would waste space forever, so they expire: a lifecycle rule aborts unfinished uploads after, say, seven days, and garbage collection frees their parts.

Step 10: Versioning

Versions of photos/beach.jpg
VersionEventWhat GET returns
v1PUT (original)v1
v2PUT (edited)v2; v1 still readable by id
v3DELETE → delete marker404; v1 and v2 still exist
—delete the markerv2 again

Versioning protects users from their own mistakes and from attackers: an overwrite or delete never destroys the previous data.

With versioning on, every put creates a new version with its own id, and the key's newest version is what a plain get returns. Older versions remain, readable by their version id.

A delete does not remove anything. It adds a delete marker as the newest version. A plain get now returns not found, but every older version is still there. To undo the delete, remove the marker, and the previous version becomes current again.

In the metadata store, versions are just more records under the same bucket and key, sorted newest first by version id, so finding the current version is reading the first record. Version ids must be ordered, so use ids that sort by time, generated by the metadata range's leader, which makes concurrent puts to the same key have a clear order: the last committed one wins.

Versioning costs storage, because nothing is ever freed, so pair it with lifecycle rules: keep old versions for thirty days, then delete them, or move them to a cheaper storage class. And for compliance, an object lock can forbid deleting a version until a date, even by the account owner, which is the strongest protection against ransomware.

Step 11: Deletes and garbage collection

Reclaiming space
  1. 01
    Delete metadataObject disappears immediately
  2. 02
    Chunk referencesCount live bytes in each sealed chunk
  3. 03
    CompactRewrite chunks that are mostly garbage
  4. 04
    DelayWait a few days before freeing, for safety

When an object is truly deleted, the metadata record goes first, and the bytes are reclaimed later.

Removing the metadata record makes the object invisible at once. But its bytes sit inside a sealed chunk, alongside other objects that are still alive, so they cannot simply be deleted.

A background process tracks, for each chunk, how many of its bytes still belong to live objects. When a chunk is mostly garbage, say less than half alive, the compactor copies the live objects into a new chunk, updates their metadata locations, and then frees the old chunk.

Build in a delay. Do not free chunks the moment they become unreferenced; wait a few days. If a bug in the metadata layer wrongly deleted references, the bytes are still there to recover. Storage systems that are proud of their durability treat their own software bugs as a failure mode too, and this delay is the cheapest protection against them.

Step 12: One upload, end to end

PUT photos/beach.jpg, 3 MB
StepWhat happens
1front end checks signature and bucket policy
2placement picks a chunk being filled on 3 nodes in 3 zones
3bytes streamed, checksummed, appended on all 3
4metadata committed: (bucket, key, v2) → chunk, offset
5200 OK with ETag and version id
laterchunk sealed; erasure coded 6+3; replicas freed

Let us walk a single put through the system.

A client puts a three megabyte photo. The front end verifies the request's signature and checks that the caller may write to this bucket.

It asks the placement service for an open chunk with room, which is currently being filled on three nodes in three zones. It streams the bytes to all three, computing a checksum as they flow. Each node appends them to its copy of the chunk and confirms, after the data is safely on disk.

Only now does the front end commit the metadata: bucket, key, a new version id, size, checksum, and the location: chunk id, offset and length. This order is essential. Bytes first, then the pointer. If the front end crashes after writing bytes but before the metadata, the bytes are orphaned garbage, harmless and later collected. The reverse order could publish a pointer to bytes that do not exist.

The client gets a two hundred with the entity tag and version id, and any read from now on sees the new photo. Later, when the chunk fills, it is sealed and erasure coded into nine fragments across the cluster, and the three full replicas are freed, cutting its storage cost in half.

Step 13: Scaling and failures

Scale and failure
  1. 01
    Add storage nodesPlacement starts using them; rebalance slowly
  2. 02
    Disk failsFragments rebuilt across thousands of disks
  3. 03
    Zone failsReads decode from fragments in other zones
  4. 04
    Metadata range failsConsensus elects a new leader in seconds
  5. 05
    Hot objectCache popular objects at the front end or edge

Scaling and failures.

Capacity grows by adding storage nodes. The placement service starts sending new chunks to them, and slowly rebalances old chunks, so the new disks are not idle while old ones are full. Metadata grows by splitting ranges.

A disk failure triggers the parallel repair we discussed. A zone failure means reads must decode from fragments in the other zones, which is slower but works, and writes go to the remaining zones. A metadata server failure is handled by the consensus group electing a new leader within seconds.

And a very popular object, a file everyone downloads at the same time, would overload the few disks holding it. Cache hot objects in memory at the front end, or put a content delivery network in front of public buckets. Because objects are immutable, caching them is easy: a cached version can never be stale for its version id.

Step 14: The parts people forget

Easy to miss
  1. 01
    Access controlBucket policies, per-object rules, block public access
  2. 02
    EncryptionEvery chunk encrypted at rest; keys per bucket
  3. 03
    MeteringBytes stored, requests and egress, for billing
  4. 04
    Event notificationsObject created or deleted, to a queue

A few details that round out a strong answer.

Access control. Buckets carry policies that say who may read or write which prefixes, checked by the front end on every request. Accidentally public buckets are one of the most common data leaks in the industry, so offer an account-wide switch that blocks public access, on by default.

Encryption. Encrypt every chunk at rest, with data keys that are themselves encrypted by a key per bucket or per customer, held in a key management service. Deleting a customer's key makes all their data unreadable at once, which is a useful way to guarantee deletion.

Metering. Customers pay for bytes stored per month, for requests, and for data sent out of the region. Every front end emits usage records, aggregated per bucket per hour, the same streaming aggregation we designed for ad clicks.

And notifications. Many systems react to new objects: a new image triggers a thumbnail job, a new log file triggers loading. After the metadata commit, publish an object created event to a queue, at least once, so customers can build pipelines on top of the store without polling the list API.

Step 15: The follow-up questions

Max asks

“How do you guarantee that a list right after a put includes the new object?”

The put is only acknowledged after its metadata is committed in the key range's consensus group, and lists read from that range's leader, or from a replica that has confirmed it has caught up to the latest commit. Since listing is a scan over the same sorted metadata, the new key is there. Strong consistency comes from the metadata store, not the storage nodes, which is another benefit of separating them.

Max asks

“Why not just use a distributed file system?”

File systems promise things object stores deliberately drop: directories that can be renamed atomically, files edited in place, locks. Those features need coordination that is hard at exabyte scale. Object storage trades them for immutable objects and a flat key space, which is what makes it simple to scale, cache and replicate. For data that is written once and read many times, which is most data, that is the right trade.

Max asks

“How would you offer a cheaper storage class for data that's rarely read?”

Move objects that have not been read for a while, or that a lifecycle rule selects, to nodes with denser, cheaper disks and a wider erasure code, say twelve plus four, which lowers overhead further. Retrieval is slower and may cost per gigabyte. For archives, power down disks or use tape, with retrieval taking hours. The metadata simply records the storage class and location, so the API stays the same.

Max asks

“How do you replicate a bucket to another region for disaster recovery?”

Asynchronously. After each committed put, an event goes to a replication queue, and workers copy the object and its metadata to the destination region's store. Copies lag by seconds to minutes, and replication status is visible per object. Because objects are immutable and versioned, replication is simple: copy each version once, and apply versions in order. Conflicts cannot corrupt data, because no version is ever modified.

Recap

Your 45 minutes
  1. 01
    0 to 5: requirementsImmutable objects; 11 nines; strong consistency
  2. 02
    5 to 10: estimates1 EB, 1 trillion objects, failures daily
  3. 03
    10 to 20: shapeFront end, metadata service, storage nodes
  4. 04
    20 to 35: durabilityErasure coding, fast parallel repair, scrubbing
  5. 05
    35 to 45: featuresListing, multipart, versioning, GC

On the clock: five minutes of requirements, separating durability from availability and noting objects are immutable. Five minutes of numbers: an exabyte, a trillion objects, dozens of failures a day.

Ten minutes on the architecture: a stateless front end, a range-partitioned metadata store, and storage nodes that hold chunks, with bytes written before the metadata points at them.

Fifteen minutes on durability: erasure coding across failure domains, the race between failure and repair, and checksums with scrubbing. And ten minutes on listing, multipart uploads, versioning with delete markers, and garbage collection. If you explain where eleven nines comes from, you will stand out.

Storage questions are full of numbers and trade-offs, and explaining them clearly takes practice out loud. You can practice this exact question with Max, our AI interviewer, at interview dry run dot com. It is free to start, and you get a scored report with what to fix. The written lesson, with every diagram, is on the site too. See you in lesson twenty-eight.

Now say it out loud

Watching an answer is not the same as giving one. Max asks this exact question, pushes back when an answer is vague and keeps time, then scores you per skill.

Practice with Max

Free: a 5-minute voice round and unlimited typed drills, with scored feedback. No card, and your camera is never recorded.