Amazon S3
medium 30 minAmazon S3 stores objects, whole files with a key and metadata, in buckets that you reach over HTTP.
When it comes up
The moments this idea belongs in a design interview, and the moments it does not.
Signals
When to bring it up
| You hear | Say | Because |
|---|---|---|
| Photos, videos, attachments | S3 for bytes, database for the key | Databases should not hold big files |
| Uploads | Presigned URL, multipart above 100 MB | App servers stay free |
| Global readers | CDN in front of a private bucket | Latency, cost, hot objects |
| Keep for years | Lifecycle to cold classes | Most data is never read again |
| Legal hold | Object Lock, compliance mode | Nobody can delete before the date |
| Two writers on one file | Conditional writes or unique keys | The latest timestamp wins otherwise |
Options
Compare your moves
One million users upload a 5 MB photo a day each. How do the bytes travel?
BreaksInto the database
- How
- A binary column.
- Limit
- 5 TB a day through the primary, its log and backups.
- Choose when
- Tiny thumbnails at most.
WorksThrough the app to S3
- How
- The app receives and forwards.
- Limit
- 5 TB a day is about 58 MB/s on average and 174 MB/s at the 3x peak through the app, with slow phones holding connections.
- Choose when
- Every byte must be inspected first.
StrongPresigned upload
- How
- The app signs, the client uploads, an event checks.
- Limit
- Objects can exist that were never confirmed: clean them up.
- Choose when
- Nearly always.
How do several workers publish a new version of a data set of 1,000 files?
BreaksOverwrite the files in place
- How
- PUT over the old keys.
- Limit
- Readers see a mixture of old and new.
- Choose when
- Never with more than one object.
WorksA new prefix and a message
- How
- Write to a dated prefix, then tell readers.
- Limit
- Readers that miss the message stay behind.
- Choose when
- One known reader.
StrongA new prefix and a pointer swap
- How
- Write all files, then replace one small pointer object with
If-Match. - Limit
- Old prefixes need a lifecycle rule.
- Choose when
- Readers must see all or nothing. This is the idea behind table formats.