Case study: design object storage
A senior-level walkthrough of an S3-style object store: metadata apart from data, an atomic PUT checked over every crash and interleaving, listing over a flat key space, durability and repair, and tail latency.
Case studyApplied27 min readUpdated
- 1 architecture diagram
- 1 sequence flow
- 2 data models
- 1 API design
- 4 code samples
- 7 interviewer follow-ups
- 4 self-checks
On this page17 sectionsHLDLLDSenior depth
Read first: A framework for system design interviews, Replication and sharding, Consistency and availability
- Separate a strongly consistent metadata service from an immutable, erasure-coded data plane, and say why.
- Make a PUT atomic by writing chunks first and committing the manifest last, with garbage collection that cannot delete live data.
- Design listing over a flat, sorted key space with prefixes, delimiters and continuation tokens.
- Plan for failure: repair queues, scrubbing, placement across failure domains and reads that use the first k fragments.
4 code samples (176 lines), collapsed so the explanation stays in focus.
Object storage is the bottom layer of most cloud systems: product images, backups, logs, datasets and static sites are all objects in buckets. The API is tiny (put, get, delete, list). The hard part is behind it: keeping trillions of objects for years without losing one, for far less than three full copies' worth of disks, while a PUT is atomic, a listing is correct and disks, racks and machines fail every day. This lesson designs an S3-style store the way a senior round would. It builds on replication and sharding, consistency and availability and erasure coding, replication and durability, and the write path and the listing are checked in tested C#.
| Ask | Why it matters |
|---|---|
| What is stored, and how big? Kilobytes, or terabyte files? | Size decides chunking, whether to pack small objects, and how uploads are resumed |
| What durability and availability? | Different targets with different costs: durability is never losing the object, availability is reading it now |
| May a read after a write see the old object? May a listing miss a new one? | Strong consistency changes the metadata design. S3 became strongly consistent in December 2020, so interviews now expect it |
| Are objects mutable? Is there versioning? | Objects are replaced whole, never edited in place, which makes chunks immutable and simplifies everything below |
| Flat keys, folders, listing, access control, presigned links? | The namespace is flat. Folders are an illusion made from key prefixes |
| Hot and cold data? One region or several? | Decides replication against erasure coding, tiers, and cross-region replication on top |
Functional: PUT, GET (with byte ranges), HEAD, DELETE, LIST by prefix with pagination, multipart upload for large objects, versioning and lifecycle rules. Non-functional: durability designed for many nines, high availability, strong consistency per object and per listing, throughput that grows with the number of clients, and a low cost per gigabyte. Out of scope: file-system semantics (rename, append, locks) and queries inside objects.
State assumptions aloud. They are illustrative.
objects: 10B at 5 MB average = 50 PB of data
metadata: 10B x 300 B (key, size, checksum, chunk list) = 3 TB
at 100 GB per shard: 30 shards, each replicated 3 ways
raw disk, 3 copies: 150 PB; 6+3 erasure coding: 75 PB
node = 24 disks x 20 TB = 480 TB: 313 nodes against 157
traffic: 100,000 requests/s x 5 MB = 500 GB/s, about 4 Tbit/s
at 25 Gbit/s per node that is 160 nodes of networkFour conclusions:
- Metadata is a database and data is a warehouse. Three terabytes of small, hot, strongly consistent records are a sharded, replicated database problem. Fifty petabytes of immutable bytes are a placement and durability problem. Separate them so each scales and fails on its own terms.
- Erasure coding halves the disks. 6+3 coding stores 1.5 times the data where three copies store 3 times: 75 petabytes instead of 150, and 156 machines saved here.
- The network is as much a limit as the disks. The aggregate bandwidth needs about as many nodes as the capacity does, so reads must spread across many nodes and a rebuild must not starve client traffic.
- Durability is the product. Customers forgive a slow request and do not forgive a lost object, so the design starts from the loss probability and works back.
| Operation | Behaviour |
|---|---|
PUT /bucket/key | Creates or replaces the whole object, atomically. Returns an ETag (a checksum) only when the object is durable |
GET /bucket/key | The object, or a byte range of it (206). Sees the latest committed version |
DELETE /bucket/key | Removes the object, or adds a delete marker in a versioned bucket. Safe to repeat |
POST uploads, PUT parts, POST complete | Multipart upload for large objects: parts in parallel, then one commit |
| Presigned URL | A time-limited signed link that lets a client without credentials do one operation (signing and expiry as in encryption, secrets and abuse) |
- query
- prefix, delimiter, max-keys (at most 1000), continuation-token
- note
- strongly consistent with PUT and DELETE; keys come back in binary order; the token is opaque to the client
- 200returns { "contents": [{ "key": "photos/2026/a.jpg", "size": 5242880, "etag": "9b2c..." }], "common_prefixes": ["photos/2025/"], "next_continuation_token": "..." }
Four properties are the contract. A PUT is atomic: a GET sees the old object or the new one, never a mixture. Objects are immutable: replacing writes a new object and a new manifest. Reads and listings are strongly consistent: after a successful PUT or DELETE, every later read and listing reflects it. And an acknowledged PUT is durable: it returns success only after enough fragments are on disk to meet the durability target.
- Front-end tier. Stateless servers that authenticate, authorise, route, verify checksums, encode and decode, and talk to the other tiers. They scale by adding machines.
- Metadata service. Maps (bucket, key, version) to a manifest and serves listings. It is range-sharded, so that listings are range scans, and each shard is replicated with consensus (Raft or Paxos), which is what makes it strongly consistent.
- Data nodes. Store immutable fragments on disks and know nothing about objects. They verify checksums on every read.
- Placement service. Chooses which nodes receive a new object's fragments, spreading them across disks, machines, racks and zones, and avoiding full or unhealthy nodes.
- Background workers. Repair lost fragments, scrub disks for silent corruption, collect garbage and apply lifecycle rules. Most of the system's reliability is here.
Microsoft's Azure storage paper describes the same split: a front-end layer, a partition layer that is range-partitioned by key and holds the metadata, and a stream layer of append-only storage underneath.
buckettext
PKSHARD KEYkeytext
up to 1 KB; keys are ordered bytes, which makes listing a range scan
PKSHARD KEYversionbigint
descending, so the newest version sorts first
PKmanifest_idbigint
sizebigint
etagtext
checksum of the whole object
statussmallint
live, delete marker
created_attimestamptz
One row per version. A PUT adds a row, and the commit of that row is the commit point of the PUT.
manifest_idbigint
PKschemetext
for example rs-6-3, or copies-3 for small and hot objects
chunk_sizeint
chunkslist
per chunk: its fragments as (node, disk, fragment id, checksum)
Fragments are immutable and named by an id. Only the manifest says which fragments make an object.
The erasure coding, replication and durability lesson builds the coder and the arithmetic. What this design takes from it:
- The scheme. Large, cold objects are split into chunks and each chunk is erasure coded, say 6+3: nine fragments on nine failure domains, any six rebuild the chunk, 1.5 times the space and three losses survived. Small or hot objects are replicated. The manifest records the scheme per object, so schemes can change.
- Repair decides durability. In the model there, 6+3 with day-long repair loses a stripe about 1.7e-12 of the time each year (11.8 nines) against 1.8e-10 for three copies (9.7 nines), and a week-long repair multiplies the loss rate by about 343. The repair queue is therefore a first-class component, ordered by how few fragments a stripe has left.
- Real failures are correlated, so placement spreads the nine fragments over racks and zones, and software rollouts, silent corruption and human error are treated as durability risks: staged rollouts, scrubbing, versioning, delete markers. Amazon states S3's durability as a design target of 11 nines, not a guarantee.
The rule is chunks first, commit last. The object does not exist until the manifest commits, and the commit is one atomic write in the strongly consistent metadata store. A crash before it leaves no object and some orphan fragments. A crash after it leaves a complete object, and a client that retries simply writes a new version. Three questions follow.
- What reclaims the orphans? A garbage collector deletes fragments that no manifest references. It must not delete the fragments of an upload that is still running, so it only collects fragments of uploads that are closed or have passed a grace period longer than any legitimate upload.
- What if an upload outlives its grace period? A slow client (a zombie) could commit after the collector has deleted its fragments, leaving a manifest that points at nothing. So the commit is conditional: it succeeds only if the upload is still open, and expiry closes it.
- How do you know it is right? Enumerate. The checker below runs every interleaving of a putter (crashing after each possible step), a collector, a timer that expires the upload and a reader, then runs one more collection pass and judges the end state. A state is broken if a reader met a manifest with missing fragments or one is left, and leaked if an unreferenced fragment survived collection.
C# · What a PUT touches: the chunks that are durable on the data nodes, the object's manifest…
using System;
using System.Collections.Generic;
using System.Linq;
// What a PUT touches: the chunks that are durable on the data nodes, the object's manifest in the metadata store (null while
// there is no object), and whether the upload is still open, which protects its chunks from garbage collection.
public sealed class Store
{
public HashSet<int> Chunks = new HashSet<int>();
public int[] Manifest;
public bool UploadOpen = true;
public int[] Candidates = new int[0]; // what the collector decided to delete, between its two steps
public int[] ReaderSnapshot; // the manifest a reader read
public bool ReaderFoundMissingChunk;
public Store Copy() { var copy = (Store)MemberwiseClone(); copy.Chunks = new HashSet<int>(Chunks); return copy; }
public bool Referenced(int chunk) => Manifest != null && Manifest.Contains(chunk);
}
public delegate void Step(Store store);
public static class PutChecker
{
// Runs every order in which four actors' steps can interleave (each actor's own steps stay in order), and for the
// putter every point at which it can crash. Then one more collection pass runs, as the next cycle would, and the end
// state is judged. Broken: a reader met a manifest whose chunks were missing, or one is left. Leaked: a chunk nobody
// references survived collection.
public static (int Orders, int Broken, int Leaked) Check(Step[] putter, Step[] collector, Step expire, Step[] reader)
{
int orders = 0, broken = 0, leaked = 0;
for (int crashAfter = 0; crashAfter <= putter.Length; crashAfter++)
{
var scripts = new[] { putter.Take(crashAfter).ToArray(), collector, new[] { expire }, reader };
void Explore(Store store, int[] next)
{
bool moved = false;
for (int actor = 0; actor < scripts.Length; actor++)
{
if (next[actor] >= scripts[actor].Length) continue;
moved = true;
var after = store.Copy();
scripts[actor][next[actor]](after);
var progress = (int[])next.Clone();
progress[actor]++;
Explore(after, progress);
}
if (moved) return;
orders++;
foreach (var step in collector) step(store); // the next collection cycle
if (store.ReaderFoundMissingChunk || (store.Manifest != null && store.Manifest.Any(c => !store.Chunks.Contains(c)))) broken++;
if (store.Chunks.Any(c => !store.Referenced(c))) leaked++;
}
Explore(new Store(), new int[scripts.Length]);
}
return (orders, broken, leaked);
}
}C# · The steps of a PUT of one object made of two chunks, and of the services around it.
using System;
using System.Diagnostics;
using System.Linq;
// The steps of a PUT of one object made of two chunks, and of the services around it.
Step writeChunk1 = s => s.Chunks.Add(1);
Step writeChunk2 = s => s.Chunks.Add(2);
Step commitIfOpen = s => { if (s.UploadOpen) { s.Manifest = new[] { 1, 2 }; s.UploadOpen = false; } }; // the atomic commit point
Step commitAlways = s => { s.Manifest = new[] { 1, 2 }; s.UploadOpen = false; }; // forgets to check that the upload is still open
Step expire = s => s.UploadOpen = false; // the grace period for an upload ends
Step scanClosed = s => s.Candidates = s.Chunks.Where(c => !s.Referenced(c) && !s.UploadOpen).ToArray(); // unreferenced chunks of closed uploads
Step scanAll = s => s.Candidates = s.Chunks.Where(c => !s.Referenced(c)).ToArray(); // ignores whether an upload is still open
Step deleteCandidates = s => { foreach (int chunk in s.Candidates) s.Chunks.Remove(chunk); };
var reader = new Step[] { s => s.ReaderSnapshot = s.Manifest, s => { if (s.ReaderSnapshot != null && s.ReaderSnapshot.Any(c => !s.Chunks.Contains(c))) s.ReaderFoundMissingChunk = true; } };
var correct = PutChecker.Check(new[] { writeChunk1, writeChunk2, commitIfOpen }, new[] { scanClosed, deleteCandidates }, expire, reader);
var commitFirst = PutChecker.Check(new[] { commitAlways, writeChunk1, writeChunk2 }, new[] { scanClosed, deleteCandidates }, expire, reader);
var collectsOpenUploads = PutChecker.Check(new[] { writeChunk1, writeChunk2, commitIfOpen }, new[] { scanAll, deleteCandidates }, expire, reader);
var commitsExpiredUploads = PutChecker.Check(new[] { writeChunk1, writeChunk2, commitAlways }, new[] { scanClosed, deleteCandidates }, expire, reader);
var neverCollects = PutChecker.Check(new[] { writeChunk1, writeChunk2, commitIfOpen }, new Step[0], expire, reader);
Debug.Assert(correct.Orders == 2_520 && correct.Broken == 0 && correct.Leaked == 0);
Debug.Assert(commitFirst.Broken == 1_314 && collectsOpenUploads.Broken == 196 && commitsExpiredUploads.Broken == 336); // each shortcut breaks objects
Debug.Assert(commitFirst.Leaked == 0 && collectsOpenUploads.Leaked == 0 && commitsExpiredUploads.Leaked == 0);
Debug.Assert(neverCollects.Orders == 105 && neverCollects.Broken == 0 && neverCollects.Leaked == 87); // no collector: nothing breaks, but fragments leak| Protocol | Interleavings | Left a broken object | Left leaked fragments |
|---|---|---|---|
| Chunks first, commit last, commit checks the upload is open, collector takes only closed uploads | 2,520 | 0 | 0 |
| Commit before the chunks are written | 2,520 | 1,314 | 0 |
| Collector ignores whether an upload is open | 2,520 | 196 | 0 |
| Commit ignores that the upload expired | 2,520 | 336 | 0 |
| No collector at all | 105 | 0 | 87 |
Each of the three shortcuts breaks objects in a different way, and none leaks, because the final pass cleans up. The reverse mistake, never collecting, breaks nothing and leaks fragments in 87 of 105 orders, which is why a collector exists at all. Real systems add details the model leaves out: fragments carry the upload id so the collector can tell their owner, collection runs from a consistent snapshot of the manifests, and deletion is delayed after a manifest is removed in case the removal is a mistake.
Multipart upload extends the same idea to large objects. The client starts an upload, sends parts in parallel (each its own chunks, each with a checksum, each retryable on its own) and completes it with the ordered list of parts. The completion is the commit: one metadata write that creates a manifest listing every part. S3 documents a limit of 10,000 parts of at most 5 GiB each; the largest object was 5 TB for many years and has been 50 TB since December 2025, which is the same 10,000 parts at the full part size. Abandoned uploads hold storage, so buckets should carry a lifecycle rule that aborts incomplete uploads.
Metadata is where an object store gets its consistency and its limits.
- Range sharding. Rows are ordered by (bucket, key), so a listing is a range scan, and a shard that grows or heats up is split in two. Hashing the key would spread load evenly but turn every listing into a scatter-gather over all shards. The cost of ranges is hot spots: keys with a common, increasing prefix (timestamps) pile writes onto one range until it splits, so systems split by load, and users are sometimes advised to spread prefixes.
- Strong consistency. Each shard is a replicated group with a leader (consensus), and metadata reads go to the leader or to a replica that has proved it is current. AWS announced in December 2020 that S3 delivers strong read-after-write consistency for reads, overwrites, deletes and listings, at no extra cost. The announcement says what, not how, so say what you would do: consensus per shard, and listings served from the same shards.
- Listing is a seek, not a scan. A flat, sorted key space gets "folders" only from a prefix and a delimiter. To list
photos/with/as the delimiter, find the first key under the prefix, and if it has a/after the prefix, report that folder once and jump past everything inside it. The continuation token is simply where to resume.
C# · A bucket's listing. Keys are flat strings kept in sorted order, and "folders" are only a…
using System;
using System.Collections.Generic;
using System.Linq;
// A bucket's listing. Keys are flat strings kept in sorted order, and "folders" are only a delimiter convention.
public sealed class ListPage
{
public List<string> Keys = new List<string>();
public List<string> CommonPrefixes = new List<string>();
public string NextToken; // null when the listing is complete
}
public sealed class KeyIndex
{
private readonly SortedSet<string> keys = new SortedSet<string>(StringComparer.Ordinal);
public int Seeks; // how many times the sorted index was searched
public void Put(string key) => keys.Add(key);
// The first key at or after `bound` that starts with `prefix`: one search in a sorted index (a B-tree or LSM seek).
private string Seek(string bound, string prefix)
{
Seeks++;
if (keys.Count == 0 || StringComparer.Ordinal.Compare(bound, keys.Max) > 0) return null;
string first = keys.GetViewBetween(bound, keys.Max).Min;
return first.StartsWith(prefix, StringComparison.Ordinal) ? first : null;
}
// One page, like S3's ListObjectsV2: the keys under `prefix`, with those that contain the delimiter after the prefix rolled
// up into one common prefix each. A page ends after maxResults keys and prefixes together, and `token` continues it.
public ListPage List(string prefix, char? delimiter, int maxResults, string token = null)
{
var page = new ListPage();
string bound = token ?? prefix;
while (true)
{
string key = Seek(bound, prefix);
if (key == null) return page;
if (page.Keys.Count + page.CommonPrefixes.Count == maxResults) { page.NextToken = bound; return page; }
int cut = delimiter == null ? -1 : key.IndexOf(delimiter.Value, prefix.Length);
if (cut < 0) { page.Keys.Add(key); bound = key + "\0"; } // the smallest string after this key
else
{
string folder = key.Substring(0, cut + 1);
page.CommonPrefixes.Add(folder);
bound = folder.Substring(0, folder.Length - 1) + (char)(delimiter.Value + 1); // jump past everything inside the folder
}
}
}
}C# · 30,000 keys in a few "folders", and the listing checked against a brute-force scan for…
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
// 30,000 keys in a few "folders", and the listing checked against a brute-force scan for many prefixes, delimiters and page sizes.
var listRandom = new Random(6);
var index = new KeyIndex();
var allKeys = new List<string>();
for (int i = 0; i < 30_000; i++)
{
string key = i % 3_000 == 0 ? $"readme{i}.md" : listRandom.Next(9) switch
{
< 6 => $"photos/{2018 + listRandom.Next(6)}/{listRandom.Next(1, 13):D2}/img_{i}.jpg",
< 8 => $"docs/{listRandom.Next(20)}/{i}.txt",
_ => $"logs/{i}.log",
};
if (!allKeys.Contains(key)) { allKeys.Add(key); index.Put(key); }
}
allKeys.Sort(StringComparer.Ordinal);
foreach (string prefix in new[] { "", "photos/", "photos/2020/", "photos/2020/03/", "docs/", "readme", "nothing/" })
foreach (char? delimiter in new char?[] { '/', null })
foreach (int pageSize in new[] { 1, 7, 100, 1_000 })
{
var keysSeen = new List<string>(); var foldersSeen = new List<string>();
string token = null;
do
{
var page = index.List(prefix, delimiter, pageSize, token);
Debug.Assert(page.Keys.Count + page.CommonPrefixes.Count <= pageSize);
keysSeen.AddRange(page.Keys); foldersSeen.AddRange(page.CommonPrefixes);
token = page.NextToken;
} while (token != null);
var under = allKeys.Where(k => k.StartsWith(prefix, StringComparison.Ordinal)).ToList();
var expectedFolders = delimiter == null ? new List<string>() : under.Where(k => k.IndexOf(delimiter.Value, prefix.Length) >= 0).Select(k => k.Substring(0, k.IndexOf(delimiter.Value, prefix.Length) + 1)).Distinct().ToList();
var expectedKeys = under.Where(k => delimiter == null || k.IndexOf(delimiter.Value, prefix.Length) < 0).ToList();
Debug.Assert(keysSeen.SequenceEqual(expectedKeys) && foldersSeen.SequenceEqual(expectedFolders));
}
// Listing the top level of the bucket visits folders, not keys.
index.Seeks = 0;
var top = index.List("", '/', 1_000);
Debug.Assert(top.CommonPrefixes.Count == 3 && top.Keys.Count == 10 && index.Seeks == 14); // folders and loose keys are visited, not all 30,000 keysThe test lists 30,000 keys in a few folders for seven prefixes, with and without a delimiter, in pages of 1, 7, 100 and 1,000, and compares every result with a brute-force scan: they matched. Listing the top level of the bucket (3 folders and 10 loose keys) took 14 searches in the sorted index, not 30,000 key visits. A listing costs time proportional to its page, however large the folder. What is expensive is anything that touches every key under a prefix: counting them, deleting a folder, or "renaming" it, which is a copy and delete of each object, because a folder is not an object.
A GET finds the manifest, reads fragments in parallel, verifies checksums and streams the bytes. Range requests map to the chunks that cover them. A healthy read of a 6+3 object needs only the six data fragments, with no decoding. Waiting for six reads is as slow as the slowest of the six, so the arithmetic of tail latency and overload applies, but the code offers a way out: ask for more fragments than needed and use the first six to arrive. In the simulation in the erasure coding lesson, waiting for the six data fragments gave a p99 of 220 ms, asking for seven and using the first six gave 40 ms for 17% more bytes read, and asking for all nine gave 20 ms for 50% more. The price is extra load on the data nodes. Hot objects are better served by a cache or a CDN in front, not by more fragments.
- Checksums everywhere. The client sends a checksum, the front-end verifies it, each fragment is stored with its own, and every read verifies it. A mismatch is treated as a lost fragment and repaired from the others.
- Scrubbing. Disks corrupt data silently. Background scrubbers read every fragment on a schedule, verify the checksums and repair mismatches, so corruption is found while the stripe still has its redundancy.
- Repair. A node that stops heartbeating is declared failed after a delay (long enough to ride out a restart). Its stripes enter a repair queue ordered by how few fragments they have left, rebuilds read k fragments and write one, and the rate is limited so client traffic is not starved. The queue's length and the age of its oldest item are the durability metrics.
- Placement. The fragments of a stripe go to different disks, machines, racks and zones, subject to free space and load. The more independent the domains, the closer real durability is to the model.
Hot, small or latency-sensitive objects are often replicated (cheap to read, no decoding, cheap to repair). Cold, large objects are erasure coded. Lifecycle rules move objects down: replicated, then erasure coded, then an archive tier with slow retrieval. Facebook's f4 paper describes the second step for warm BLOBs: replication of 3.6 times in its first-generation store came down to 2.8 or 2.1 times with Reed-Solomon coding inside a data center and an XOR code across data centers.
Small objects are a problem of their own: a file system or a metadata service pays a fixed cost per object. Facebook's Haystack packs many photos into large append-only files and keeps a compact in-memory index of offsets, about 10 bytes of memory per stored photo according to its authors (about 40 for the four sizes kept of one upload), against 536 bytes for an XFS inode. Object stores do the equivalent: pack small objects into larger containers and index them.
| Case | What goes wrong | Response |
|---|---|---|
| A disk or node fails | Fragments are missing, so the stripe is closer to loss | Detect, queue the repair by remaining redundancy, rebuild with a rate limit |
| Repair falls behind | The window for overlapping failures grows, and loss grows as the repair time to the power m | Spare capacity for repair, priority by risk, alert on the backlog |
| A rack or zone is lost | Many fragments disappear together | Place each stripe's fragments across racks and zones |
| Silent corruption | A fragment returns wrong bytes | Checksums on every read, scrubbing, repair from the other fragments |
| A crash during a PUT | Orphan fragments, no object | Chunks first and commit last, a collector with a grace period |
| A zombie writer commits late | A manifest points at collected fragments | A commit that is conditional on the upload still being open |
| A hot key range | One metadata shard saturates | Split ranges by load, cache hot objects, spread key prefixes |
| A slow node | Tail latency on reads | Read more fragments than needed, avoid slow nodes |
| A mistaken delete or overwrite | Data is gone although no disk failed | Versioning, delete markers, object lock, a delay before collection |
| Abandoned multipart uploads | Parts occupy storage forever | A lifecycle rule that aborts incomplete uploads |
Interviewer follow-upL5How would you store a 5 TB file?How to answer
Multipart upload: the client splits it into parts, uploads them in parallel and retries any part on its own, each part is chunked and erasure coded like a small object, and a final complete call commits a manifest listing the parts, which is the single atomic step. The part size trades parallelism against per-part overhead. Reads use byte ranges over the same parts. Add a lifecycle rule to abort uploads that never complete.
Interviewer follow-upL5Replication or erasure coding?How to answer
Replication reads and repairs cheaply and suits small, hot objects, but costs three times the space. Erasure coding stores 1.4 to 1.5 times the data and, with fast repair, loses data less often, but a repair reads k fragments, a read touches k nodes, and tiny objects stripe badly. Use replication for the hot and small, erasure coding for the large and cold, and move objects between them by lifecycle rules.
Interviewer follow-upL6How do you make a PUT atomic?How to answer
Write all the chunks first, then commit one manifest row in the strongly consistent metadata store: that single write is the commit point. Before it there is no object, after it every read sees the whole object. A crash before the commit leaves only orphan fragments, which a garbage collector removes, but only for uploads that are closed or past a grace period, and the commit itself is conditional on the upload still being open, so a late writer cannot point a manifest at fragments that were collected.
Interviewer follow-upL6A disk dies. What happens?How to answer
The node's heartbeats stop, and after a delay it is declared failed. Every stripe with a fragment on it enters a repair queue ordered by how few fragments it has left. Workers read k surviving fragments of each stripe, rebuild the lost one and store it on another disk in a different failure domain, at a rate that leaves room for client traffic. Durability depends on how quickly the queue drains, because loss probability grows with the repair time to the power of the number of parities.
Interviewer follow-upL6How do you list a bucket with a billion keys?How to answer
Keep keys in sorted order in a range-sharded metadata store, so a listing is a range scan. Return pages of at most 1,000 entries with a continuation token that says where to resume, roll keys up by prefix and delimiter by seeking past each folder, and keep the cost proportional to the page, not the folder. Split hot ranges by load. Avoid operations that touch every key under a prefix, because there is no folder object to count or rename.
Interviewer follow-upL7How would you design for eleven nines?How to answer
Start from the model: durability is the probability that more fragments fail than the code tolerates before repair finishes, so choose the code and the repair speed together (6+3 with day-long repair gives about 11.8 nines for independent disks, and a week gives 9.2). Then attack what the model leaves out: correlated failures (spread fragments across racks and zones, replicate across regions for the most critical data), silent corruption (checksums and scrubbing), software bugs (staged rollouts and canaries), and human error (versioning, delete markers, object lock). Treat the figure as a design target, as Amazon does, and measure repair backlog and scrub results continuously.
Interviewer follow-upL7How do you handle billions of tiny objects?How to answer
A per-object cost in metadata or on disk dominates when objects are small. Replicate rather than erasure code them, pack many into a larger container and index their offsets (the Haystack approach), batch metadata updates, and consider whether the workload wants a key-value store instead. Limit or charge by request count as well as bytes, because the request rate is what such workloads stress.
- Clarify: object sizes, durability and availability targets, consistency, listing, mutability and tiers.
- Estimate: data, metadata and node counts, and the saving from erasure coding.
- Contract: put, get with ranges, delete, list with prefix and delimiter, multipart; atomic, immutable, strongly consistent, durable before the acknowledgement.
- Draw it: front-end tier, metadata service, placement, data nodes, background workers.
- Durability: erasure coding for the large and cold, repair time as the lever, failure domains and scrubbing.
- PUT: chunks first, commit last, a collector that cannot delete live data, multipart.
- Listing and reads: range-sharded metadata with seeks, and reads of more fragments than needed for the tail.
Object storage joins a strongly consistent, range-sharded metadata service to an immutable, erasure-coded data plane through a manifest. Erasure coding stores 1.5 times the data for three survivable losses instead of three times for two, and durability is decided by repair speed: the loss probability grows with the repair time to the power of the parity count, and the model is an upper bound because real failures are correlated. A PUT writes chunks first and commits the manifest last, with a conditional commit and a collector that only takes closed uploads: each shortcut broke objects in hundreds or thousands of the 2,520 interleavings checked, and the correct protocol in none. Listing is a seek in a sorted key space, so its cost follows the page and not the folder, while anything that touches every key under a prefix is expensive. Reading more fragments than needed and using the first k cuts the tail.
Try answering out loud before you reveal each answer.
QuestionWhy keep metadata in a separate service from the data nodes?Reveal answer
They are different problems. Metadata is terabytes of small, hot, strongly consistent records that need ordered range scans and consensus. Data is petabytes of immutable bytes that need placement, repair and throughput. Separate services scale, fail and are tuned independently, and the manifest is the only link between them.
QuestionA front-end crashes after writing six of nine fragments and before the commit. What does a reader see, and what happens to the fragments?Reveal answer
The reader sees no new object (or the previous version), because the manifest is the commit point and it was never written. The fragments are orphans. After the upload expires, the garbage collector, which only collects fragments no manifest references and whose upload is closed, deletes them.
QuestionA client's upload is slow and exceeds the grace period, yet it then commits. What goes wrong without a conditional commit, and what prevents it?Reveal answer
The collector may already have deleted the upload's unreferenced fragments, so the manifest that the late commit creates points at missing fragments and the object is broken. Making the commit conditional on the upload still being open, with expiry closing the upload, makes the late commit fail, and the client retries with a new upload.
QuestionWhy is listing a folder cheap, and what is expensive?Reveal answer
Keys are in sorted order, so a listing seeks to the first key under the prefix and, with a delimiter, jumps past each folder, so the cost follows the page size, not the number of keys in the folder. Anything that touches every key under a prefix is expensive: counting them, deleting a folder, or renaming it, which copies and deletes every object because a folder is not an object.
- Amazon Web Services, Data protection in Amazon S3 (opens in a new tab), multipart upload limits (opens in a new tab), Amazon S3 increases the maximum object size to 50 TB (opens in a new tab) (December 2025), and the announcement Amazon S3 now delivers strong read-after-write consistency automatically for all applications (opens in a new tab) (December 2020). The multipart upload limits are in the multipart upload overview (opens in a new tab).
- Brad Calder and others, Windows Azure Storage: A Highly Available Cloud Storage Service with Strong Consistency (opens in a new tab), SOSP 2011: the front-end, partition and stream layers.
- Subramanian Muralidhar and others, f4: Facebook's Warm BLOB Storage System (opens in a new tab), OSDI 2014, and Doug Beaver and others, Finding a Needle in Haystack: Facebook's Photo Storage (opens in a new tab), OSDI 2010.
- Cheng Huang and others, Erasure Coding in Windows Azure Storage (opens in a new tab), USENIX ATC 2012, and Daniel Ford and others, Availability in Globally Distributed Storage Systems (opens in a new tab), OSDI 2010: repair cost and correlated failures, covered in the erasure coding lesson.