Requirements of a blob store
medium 24 minBefore building a store for photos, videos and backups, decide what it must do, how well, and how much of it.
See it run
Follow one upload, estimate the size, and see which promise each failure tests.
Operations
One upload
Six steps that turn a PUT into a promise.
Step 1 of 6
Client initiates
PUT photos/a.jpg
The client sends a PUT with the bytes and the key it chose.
Step 1: Client initiates
def put(client, bucket, key, data): authorize(client, "put", bucket, key) blob_id = new_id() # the key stays the client's write_to_zones(blob_id, chunks(data)) metadata.commit(bucket, key, blob_id) return 200, etag(data)- Decides
- Write path
- You leave with
- A safe order
- Name first
- a name may point at nothing
If someone asks when the object exists, answer: when the metadata commit succeeds.
In the real world
The same requirements of a blob store doing real jobs. Pick one and step through it.
A team ships without asking for the largest file.
Step 1 of 4
Launch
2 MB
Photos of 2 MB go through one PUT. All is well.
Step 1: Launch
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Reporting success before the bytes are safe
criticalA crash after the answer loses a file the user believes is stored.
Wrongreply(200)write_to_zones(data)Rightwrite_to_zones(data)metadata.commit(key)reply(200)One word for two promises
majorAn available store can lose data, and a durable store can be unreachable.
Wrongslo = {"reliable": "99.99%"}Rightslo = {"durability": "11 nines", "availability": "99.99%"}Fixed part size
major8 MB parts stop at 80 GB because of the 10,000 part limit.
Wrongpart = 8 * MBRightpart = max(8 * MB, ceil(size / 10_000))Reading one page of a listing
minorA listing returns at most 1,000 keys on S3. The rest is silently missed.
Wrongkeys = list(bucket)Rightwhile True: page, token = list(bucket, token) use(page) if not token: break
Interview tips
Ask in this order
- What is stored and how large?
- Who writes, who reads, how often?
- What must never happen?
- What is not our job?
Memory trick: SPED
- Scalability
- Presigned URLs
- Eleven nines
- Distributed
Turn wishes into numbers
- Durability a year
- Availability a month
- First byte in ms
- Bytes a year
Check before you quote
- Limits change: 5 TB became 50 TB.
- Read the product's own page.
- Say the date you checked.