AlgoViz

Amazon S3

medium 30 min

Amazon 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 hearSayBecause
Photos, videos, attachmentsS3 for bytes, database for the keyDatabases should not hold big files
UploadsPresigned URL, multipart above 100 MBApp servers stay free
Global readersCDN in front of a private bucketLatency, cost, hot objects
Keep for yearsLifecycle to cold classesMost data is never read again
Legal holdObject Lock, compliance modeNobody can delete before the date
Two writers on one fileConditional writes or unique keysThe 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.