Object storage
What we are building
Section titled “What we are building”An object store keeps objects, files of any size, in buckets under a key, and gives them back. Backups, photos, logs and the pastes of the pastebin all end up in one. Unlike the other case studies, its first requirement is not speed but a promise: an object that was stored is still there, years later.
Functional requirements. PUT an object under a key in a bucket. GET it by its key. DELETE it. LIST the keys of a bucket in order, with a prefix. Versioning, access control, lifecycle rules and multi-region copies are left out.
Non-functional requirements. These are targets chosen for this lesson. Durability: the probability that an object is lost in a year should be around 1 in 100 billion, the 99.999999999% (11 nines) that Amazon documents as the design goal of its standard storage class. A GET after a successful PUT of the same key returns the new object. Availability matters, but a short outage is better than a lost object.
Scale. 2 billion objects of 1 MB, 2 PB, 12,000 requests per second at the peak, 9 reads for every write.
Mental model. An object store is a very large number of unreliable disks, a small database that remembers where everything is, and a promise built from arithmetic: how many disks must fail, in how short a time, for an object to be lost. Most of the design is making that arithmetic come out right at a price you can pay.
Estimate before you design
Section titled “Estimate before you design”The method is the one from storage and retention. A storage node has 12 disks of 20 TB, so 240 TB. We fill nodes to 5/6, about 83%, so that there is room to rebuild and to grow: 200 TB of data per node.
| Quantity | Working | Result |
|---|---|---|
| Data | 2 billion × 1 MB | 2 PB |
| Raw bytes with 3 copies | 2 PB × 3 | 6 PB |
| Nodes with 3 copies | 6 PB ÷ 200 TB | 30 |
| Raw bytes with erasure coding, 10 data and 4 parity fragments | 2 PB × 14 ÷ 10 | 2.8 PB |
| Nodes with erasure coding | 2.8 PB ÷ 200 TB | 14 |
| Requests at the peak | 9 reads + 1 write in 10 | 10,800 GET and 1,200 PUT per second |
| Reads out at the peak | 10,800 × 1 MB | 10.8 GB/s, 86 Gbit/s |
| Disk operations per request, 3 copies | 0.9 × 1 + 0.1 × 3 | 1.2 |
| Disk operations per second, 3 copies | 12,000 × 1.2 | 14,400 |
| Nodes needed for those operations | 14,400 ÷ 800 | 18 |
| Disk operations per request, erasure coding | 0.9 × 10 + 0.1 × 14 | 10.4 |
| Disk operations per second, erasure coding | 12,000 × 10.4 | 124,800 |
| Nodes needed for those operations | 124,800 ÷ 1,333 | 94 |
| Metadata | 2 billion × about 200 bytes | 400 GB |
The 20 TB disks, the 83%, the 800 operations per second and the 1,333 are assumptions: a disk spends about 8 ms finding data and then reads 1 MB at 150 MB/s, about 15 ms for each operation, and 12 disks work at once, so a node does 12 ÷ 0.015 = 800 operations per second. A fragment of 100 KB takes 8 ms plus 0.7 ms, about 9 ms, so a node does 12 ÷ 0.009 = 1,333. The last rows are the lesson in one table. With three copies, the bytes decide the number of nodes: 30, against 18 for the operations. With erasure coding, the operations decide: 94 nodes, three times more than three copies, although it stores fewer bytes. The section on erasure coding explains why.
The API and the data
Section titled “The API and the data”PUT /bucket/photos/2026/cat.jpg (the bytes) 200 OK ETag: "…"GET /bucket/photos/2026/cat.jpg 200 OK (the bytes)DELETE /bucket/photos/2026/cat.jpg 204 No ContentGET /bucket?prefix=photos/2026/&max-keys=1000 200 OK (keys in order)The metadata is one record for each object, in the metadata service.
| Field | Meaning |
|---|---|
bucket, key |
The primary key. Records are ordered by it, which makes LIST a range scan. |
version |
Which write this record is. |
size, checksum, created_at |
How big, a hash of the content for detecting damage, and when. |
placement |
Where the copies (or fragments) are: node and disk for each. |
The data is bytes in files on the storage nodes, named by an identifier that the record holds. The record says whether the object exists; the bytes are only bytes.
Four stages, each forced by a number
Section titled “Four stages, each forced by a number”The lab grows the design one decision at a time. Every figure is model output from illustrative inputs; the model notes under the lab say what it leaves out. Erasure coding is not a stage, for a reason the lab’s numbers will show.
A service that stores objects, files of any size, under a bucket and a key, and returns them on a GET. Its first job is never to lose one. Step through four stages, each adding the one thing the previous stage’s numbers called for (separate metadata, three copies, a sharded metadata service), and raise the load to see what breaks. Erasure coding, the other way to be durable, is worked out in the lesson.
Start simple: one server with local disks
Design load of this stage: 500 req/s
- What we add
- One server with 12 disks of 20 TB keeps every object as a file and finds it from its key with an index on the same machine. A GET reads the file; a PUT writes it and records the key.
- Why: the number that forced it
- Reading 1 MB keeps a disk busy for about 15 ms (8 ms to find the data, 7 ms to read it at 150 MB/s) and the 12 disks work at once, so the server does 12 ÷ 0.015 = 800 requests per second. At 500 it is at 62.5%. All the objects, up to 12 × 20 TB = 240 TB, fit in the machine.
- What it costs
- One copy of everything. A disk fails with a probability of about 2% a year (illustrative; real rates depend on the model and the age), so each object has a 2% chance a year of being lost. Losing the machine loses them all.
- What breaks next
- At twice the load, 1,000 requests per second, demand is 125% of capacity and a fifth of the requests fail. More disks than one machine holds are needed, and with several machines something has to know which machine holds which object.
Each dot stands for many requests. The numbers show the real rate.
No bottleneck: every component has headroom.
Figures at this load
- Busiest component
- Storage server (data and index)Busy63% of its capacity
- p95, whole request
- 46 ms
- p99, whole request
- 69 ms
- Requests served
- 100%500 req/s
- Requests failed
- 0%0 req/s
- Bottleneck
- none
| Component | State | Utilisation | Offered (req/s) | Served (req/s) | Rejected (req/s) | p50 | p95 | p99 |
|---|---|---|---|---|---|---|---|---|
| Applications | Healthy | <1% | 500 | 500 | 0 | 0 ms | 0 ms | 0 ms |
| Storage server (data and index) | Busy | 63% | 500 | 500 | 0 | 11 ms | 45 ms | 69 ms |
- Traffic
- 500 req/s
- Successful
- 500 req/s
- Error rate
- 0%
- Mean latency
- 16 ms
All stages at a glance
Each cell is the engine’s steady state for that stage at that load: the busiest component, how much of its capacity it uses, and the share of requests that fail.
| Stage | Design load | Design load | 2× the design load | 4× the design load |
|---|---|---|---|---|
| 1. Start simple: one server with local disks | 500 req/s | 500 req/sStorage server (data and index): 63%none fail | 1K req/sStorage server (data and index): 125%20% fail | 2K req/sStorage server (data and index): 250%60% fail |
| 2. Separate metadata from data | 5K req/s | 5K req/sStorage nodes: 62%none fail | 10K req/sStorage nodes: 125%20% fail | 20K req/sStorage nodes: 250%76% fail |
| 3. Keep three copies of every object | 8K req/s | 8K req/sMetadata service: 67%none fail | 16K req/sMetadata service: 133%25% fail | 32K req/sMetadata service: 267%79% fail |
| 4. Shard and replicate the metadata | 12K req/s | 12K req/sStorage nodes: 60%none fail | 24K req/sStorage nodes: 120%20% fail | 48K req/sStorage nodes: 240%69% fail |
Illustrative values, not benchmarks of any real product.
Model notes
Assumptions
- Requests arrive at random, as a Poisson process, at a constant average rate.
- Each node is one queue, served first-come first-served by several identical slots (instances × concurrency).
- Service times are random with the stated mean; by default they are exponentially distributed.
- Each node is analysed separately, with the traffic it receives treated as Poisson.
- Every number is illustrative model output, not the benchmark of a real object store: nodes of 12 disks of 20 TB, 8 ms to find data on a disk and 150 MB/s to read it, objects of 1 MB, 9 requests in 10 are reads, a metadata query of 1 ms, a disk failure rate of 2% a year.
- The data is 2 billion objects of 1 MB, 2 PB. Stage 1 holds up to 240 TB; from stage 2 the lab is sized for the 2 PB.
Simplifications
- Above capacity there is no steady state. The model switches to a fluid approximation: the node serves at capacity, its queue grows until it reaches its limit, and further requests are rejected.
- Percentiles assume an exponential tail. A service-time variability other than exponential changes the mean wait but not the shape of the tail.
- A node frees its slot as soon as it has done its own work, before waiting on the services it calls. Real thread-per-request servers hold the slot, so a slow dependency exhausts them faster than this model shows.
- A request calls its dependencies one after another. Parallel fan-out is not modelled.
- When a caller times out and gives up, the callee still finishes the work, so abandoned requests keep consuming capacity.
- Retries add load. Their backoff and jitter decide when that load arrives, which only the per-request simulation shows.
- Retry feedback is solved from the healthy starting point, so it finds one stable outcome. Systems that stay stuck in overload after the cause is gone are not shown.
- A throughput limit (for example maximum writes per second) is modelled as slower service, not as a separate rate limiter.
- A caller’s timeout counts the mean time its dependencies take, not their full distribution.
- Latency percentiles for a whole request are estimated, over every request, including those that are rejected and fail quickly. The mean is exact, and the percentiles come from a gamma distribution that has that mean and the variance of the time spent in each component.
- The lab shows the path of a request under a steady load. Failed disks, the rebuild of lost copies and the background work that repairs them are not modelled; the lesson works out how fast a rebuild has to be.
- A metadata shard is one component with a mean service time of 1.5 ms. The votes between its 3 machines are not simulated, and the 3 machines are not counted in the lab’s capacity.
- Every disk operation on a 1 MB object takes 15 ms on average. Real stores hold many small objects and a few huge ones, and for a small object the time is almost all finding the data.
- Erasure coding is not a stage. It is cheaper than copies only for data that is rarely read, so the lesson works it out separately with its own numbers.
Parameter values are illustrative. They are not benchmarks of any real product.
Stage 1, one server with local disks. The server keeps each object as a file and finds it by key with an index on the same machine. A 1 MB read keeps a disk busy for about 15 ms, so 12 disks do 800 requests per second. At 500 it is at 62.5%. At twice the load, 1,000, demand is 125% of capacity and a fifth of the requests fail. The data, up to 240 TB, sits on one machine with one copy: each disk has a 2% chance a year of failing and taking its objects with it.
Stage 2, metadata and data apart. The objects spread over 10 storage nodes, 2.4 PB, and a metadata database maps each key to its node. At the design load of 5,000 requests per second the storage nodes are at 62.5% of their 8,000 and the metadata database at 41.7% of its 12,000 queries per second. At twice the load, 10,000, the storage nodes are at 125%.
Stage 3, three copies. The cluster grows to 30 nodes to hold 6 PB. A request costs 1.2 disk operations on average, so 30 nodes do 24,000 operations per second, which is 20,000 requests per second. At the design load of 8,000, the storage nodes are at 40% and the metadata database at 66.7%. At twice the load, 16,000, the storage nodes are at 80% but the single metadata database is asked for 16,000 queries per second against 12,000: 133%.
Stage 4, sharded and replicated metadata. The metadata is split into 4 shards, each kept on 3 machines that agree by consensus. A write waits for a majority, so a query costs 1.5 ms on average instead of 1 ms, and 4 shards answer 42,667 per second. At the design load of 12,000, the metadata is at 28.1% and the storage nodes at 60%. At twice the load, 24,000, the storage nodes are asked for 28,800 operations per second against 24,000, 120%, and the metadata is at 56%. The limit is back in the data, and in the price of three copies.
Durability: the arithmetic
Section titled “Durability: the arithmetic”A disk fails with some probability each year. The Backblaze drive statistics report annual failure rates of the order of 1 to 2% for the drives in its data centres; we use 2%, written λ. With one copy an object is lost when its disk fails: 2% a year. Of 2 billion objects, 40 million are lost every year. That is stage 1.
With several copies, a failure is not the end: the lost copy is rebuilt from the others in a time w, the rebuild window. The object is lost only if enough further copies fail inside that window. The model is this: the first failure of any of the n copies happens at a rate of n × λ a year. It opens a window of w. The object is lost if k more of the remaining n − 1 copies fail inside it, and each does so with probability λ × w when w is a small part of a year. So the loss per object per year is about n × λ × C(n − 1, k) × (λ × w)^k. This assumes the failures are independent and the window is short, and counts the failures that start inside the first window only; it is a clear approximation and not a promise.
Take w = 24 hours, so λ × w = 0.02 ÷ 365 = 5.5 in 100,000.
- Two copies (n = 2, k = 1): 2 × 0.02 × 5.5 × 10^-5 = 2.2 in a million a year. Of 2 billion objects, about 4,400 are lost every year.
- Three copies (n = 3, k = 2): 3 × 0.02 × (5.5 × 10^-5)^2 = 1.8 in 10 billion a year, 99.99999998%. Of 2 billion, 0.36 objects a year, one every 3 years.
- Erasure coding, 10 data and 4 parity (n = 14, k = 4, five fragments must be lost): 14 × 0.02 × 715 × (5.5 × 10^-5)^4 = 1.8 in a million billion a year, about 2 × 10^-15.
The three copies come close to the target of 1 in 100 billion (10^-11) but do not reach it at 24 hours. The rebuild window enters as its square, so halving it divides the loss by four. At w = 6 hours, three copies lose 1.1 × 10^-11 an object a year, which is the 11 nines. At w = 10 days, 240 hours, three copies lose 1.8 × 10^-8, and 2 billion objects lose 36 a year.
| Scheme | Raw bytes per byte | Loss per object per year, w = 24 h | Objects lost per year of 2 billion |
|---|---|---|---|
| 1 copy | 1 | 2 × 10^-2 | 40 million |
| 2 copies | 2 | 2.2 × 10^-6 | about 4,400 |
| 3 copies | 3 | 1.8 × 10^-10 | 0.36 |
| 3 copies, w = 6 h | 3 | 1.1 × 10^-11 | 0.023 |
| Erasure coding 10+4 | 1.4 | 1.8 × 10^-15 | 0.0000036 |
| Erasure coding 10+4, w = 240 h | 1.4 | 1.8 × 10^-11 | 0.036 |
How fast can a disk be rebuilt? A 20 TB disk, rebuilt by one stream at 150 MB/s, takes 20 TB ÷ 150 MB/s = 37 hours. If the copies of its objects are spread over 100 other disks, each giving 20 MB/s, the rebuild runs at 2 GB/s and takes 2.8 hours. Spreading the placement is therefore the first lever on w. For erasure coding the repair is heavier: to recreate one lost fragment, 10 fragments are read, so rebuilding the same disk reads 200 TB and, at the same 2 GB/s, takes 28 hours. Even so, the table shows that erasure coding with a window ten times longer is as durable as three copies are with theirs in 24 hours.
Two limits matter more than the decimals. First, the failures are not independent. A rack, a power feed, a batch of disks from one production run, a firmware bug or an operator mistake takes out many copies together. The defences are to put the copies of an object in different failure domains (3 copies in 3 racks, so one rack failure costs one copy), and to limit how many different sets of disks hold copies: the copysets paper shows that placing each object’s copies on random disks makes it likely that some set of disks holds all copies of some object when three disks fail together, and proposes restricting the sets. Second, a copy that is silently damaged is not a failed disk. Every object has a checksum in the metadata, a read verifies it, and a background scrub reads everything on a schedule: 6 PB every 30 days is 6 PB ÷ 2,592,000 s = 2.3 GB/s of reading.
Erasure coding: fewer bytes, more operations
Section titled “Erasure coding: fewer bytes, more operations”Erasure coding cuts an object into k data fragments and computes m parity fragments from them with a code such as Reed-Solomon, so that any k of the k + m fragments rebuild the object. With k = 10 and m = 4, the object survives the loss of any 4 of its 14 fragments and costs 1.4 times its size, against 3 times for three copies and 2 failures survived. The Ceph documentation describes the same choice of k and m for an open source store.
The price is paid in disk operations. A read of a 1 MB object from a copy is one operation of 15 ms. From an erasure-coded object it is 10 operations on 10 disks, of about 9 ms each: about 90 ms of disk time, 6 times more. The time to find the data is paid 10 times, because each fragment is a separate small read. This is why the estimate needed 94 nodes with erasure coding and 30 with copies: the disks are busy finding fragments. For large objects, the picture changes: a 64 MB object costs 8 ms plus 427 ms to read from a copy, 435 ms, and 10 fragments of 6.4 MB cost 10 × (8 + 43) = 507 ms, only 17% more disk time, for less than half the bytes. The same reasoning is why Haystack packs many small photos into large files: for a small object, finding it is nearly all the cost.
Repair is the other price. Rebuilding a lost fragment reads 10 others; rebuilding a lost copy reads 1. Azure’s local reconstruction codes add a few extra fragments so that most single failures can be repaired by reading fewer fragments, trading some storage for less repair traffic, and Facebook’s f4 uses erasure coding for warm data that is rarely read.
So the decision follows the data’s temperature. Take a cold archive of 20 PB read 100 times a second. With 3 copies it needs 60 PB, which at 200 TB per node (240 TB, 83% full) is 300 nodes. With 10+4 coding it needs 28 PB, which is 140 nodes, and its 100 × 10 = 1,000 operations a second are nothing to a cluster of that size. Now take this lesson’s workload, 2 PB with 12,000 requests per second: even if 90% of the bytes are cold and get 1% of the reads, the hot 10% needs 18 nodes for its operations and the cold 90% needs 13 for its bytes, 31 against 30 for three copies everywhere. The bytes saved are spent on the operations. Erasure coding pays when the nodes would be full of bytes and idle in operations, and that is cold or large data. New objects are usually written as copies and moved into erasure coding after they have cooled.
Consistency: the commit makes the object exist
Section titled “Consistency: the commit makes the object exist”The metadata record is the commit point. A PUT goes in a fixed order:
- The front-end API picks an identifier and writes the data to the storage nodes: 3 copies, or 14 fragments. It waits until the copies are safely on disk.
- It commits the metadata record. The record’s shard is replicated by consensus, and the write counts when a majority of the 3 machines has it.
- Only then does it answer 200 to the client.
A GET reads the record from the shard’s leader, so it sees every committed write, and then reads the data from a node the record names. A GET after a successful PUT therefore returns the new object: strong read-after-write consistency. This was not always what the biggest object store offered. Amazon S3 was eventually consistent for overwrites and deletes until it announced strong read-after-write consistency in December 2020. An overwrite is a new record that replaces the old one atomically, and the old bytes are collected later. The cost of reading the leader is the 1.5 ms of stage 4 and the fact that a shard without its majority refuses writes.
The order, data first and record second, is the same rule as in the pastebin lesson, and for the same reason. A crash between the two steps leaves bytes that no record names: an orphan, invisible, which a background job finds by comparing the node’s files with the records and deletes. The opposite order would publish a record that points to bytes that do not exist.
LIST decides how the metadata is cut. If the records are split by key range, LIST is a range scan on one or two shards, but keys that arrive in order, such as timestamps, all hit the last range. Amazon’s documentation sets per-prefix request limits (see optimizing performance) and recommends spreading keys across prefixes. If the records are split by a hash of the key, writes spread evenly, but LIST has to ask every shard and merge the results.
What happens if a disk fails
Section titled “What happens if a disk fails”The cluster notices, marks the disk’s copies as missing and starts rebuilding them from the others, spread over many disks so that the window is short. While it runs, every object that had a copy on the disk has one copy fewer. For three copies that is the exposure of the table: the loss needs 2 more disks to fail inside the window, 1.8 in 10 billion for a year at 24 hours. The practical rules follow. Make the rebuild fast and give it priority over everything but reads. Alarm when the number of objects with fewer than 3 healthy copies stops falling. And replace the disk quickly, because the cluster is running with less margin until the lost bytes are rewritten.
What happens if a rack is lost
Section titled “What happens if a rack is lost”If the 3 copies of an object are in 3 different racks, a rack failure costs at most one copy of any object, and the object is still readable from the other two. The reads that went to the lost rack move to the others. The cluster rebuilds the missing copies into the remaining racks, and that is a large amount of data: a rack of 10 nodes of 240 TB holds 2.4 PB to rewrite, which at 2 GB/s takes 14 days, far beyond the 24 hours of the table. This is why a real design has many racks, so that the rebuild runs on many disks at once, and why it measures the window for a rack, not only for a disk. If two copies were in the same rack, the failure of that rack would leave one copy, with the window of 14 days.
What happens if the metadata loses its majority
Section titled “What happens if the metadata loses its majority”A metadata shard with 3 machines tolerates one failure. If two are lost, the shard cannot commit, so every PUT whose key belongs to it fails, and a GET cannot be checked against the leader. Objects of other shards are not affected. This is the price of strong consistency: a part of the key space stops answering, rather than answering with something that might be stale. It also shows why the metadata must be small and well protected: it is 400 GB for 2 billion objects, and losing it while keeping the bytes would leave 2 PB of objects that nobody can name.
Trade-offs
Section titled “Trade-offs”| Decision | What you gain | What you pay | When to choose otherwise |
|---|---|---|---|
| Metadata apart from data | A small fast database that decides what exists; cheap bulk storage for the bytes | Two systems, an order of writes, orphans to collect | One node, a small amount of data: the filesystem is the metadata |
| Three copies | Simple, fast reads (one operation), any copy can serve; loss of 1.8 in 10 billion a year at a 24 hour rebuild | 3 times the bytes: 6 PB for 2 PB; every PUT writes 3 copies | Cold or large data, where the bytes dominate the cost |
| Erasure coding 10+4 | 1.4 times the bytes; survives 4 lost fragments | 10 operations per read, 10 times the repair traffic, CPU for the coding; a slow disk delays a read of 10 fragments | Small or frequently read objects: copies, or pack the small objects into large ones |
| Spreading the placement widely | A short rebuild window, which enters the loss as its square | More sets of disks that can hold all copies of an object (copysets) | A small cluster, where there is nothing to spread over |
| Consensus-replicated metadata | A GET after a PUT sees the object; a failure of one machine is invisible | Each lookup costs more (1.5 ms against 1 ms in the lab); a shard without a majority refuses writes | Data where an old answer is acceptable and availability matters more |
Defend your design
Section titled “Defend your design”An interviewer asks you to design an object store like S3. The weak answers say “store files on many servers and replicate them”. A good answer separates metadata from data, gives a probability for losing an object, compares copies with erasure coding on both bytes and operations, and says what a GET sees right after a PUT. Write your answer first.
Interview question
Writing and reviewing an answer needs JavaScript.
The interviewer asks
Design an object store like Amazon S3, where an object must almost never be lost. Disks fail about 2% a year: how do you get from there to a loss rate that is practically zero, and what does it cost?
Assume 2 billion objects of 1 MB (2 PB), 12,000 requests per second at the peak, 9 reads for each write, and storage nodes of 12 disks of 20 TB that do about 800 operations of 1 MB per second.
Write your answer first. The strong answer unlocks once you have written a real attempt.
0 of 100 characters written to unlock the strong answer
- 2 billion objects of 1 MB are 2 PB. Three copies need 6 PB, 30 nodes at 83% full; erasure coding with 10 data and 4 parity fragments needs 2.8 PB, 14 nodes for the bytes.
- One server does 800 requests per second at 15 ms a disk operation. Ten storage nodes do 8,000, thirty nodes with three copies do 20,000 requests per second, and 4 metadata shards do 42,667 queries per second against 12,000 for one database.
- With a 2% yearly disk failure rate, one copy loses 2 objects in 100 a year, two copies 2.2 in a million, three copies 1.8 in 10 billion (a rebuild of 24 hours), and 10+4 erasure coding 1.8 in a million billion.
- The rebuild window enters as a square for three copies: 6 hours gives 1.1 in 100 billion, the 11 nines. Spread the placement to shorten it; spread the copies over racks because real failures are correlated.
- Erasure coding turns one read into 10 and a repair into 10 reads: 94 nodes against 30 for this workload. It pays for cold or large data, such as a 20 PB archive that needs 140 nodes instead of 300.
- Data is written first and the metadata record is committed second, by a majority of its shard; a GET reads the committed record, so it sees the last PUT. A crash in between leaves an orphan to collect.
Next: the recap and quiz, which pulls the fourteen designs together. This is the last case study.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.