AlgoViz

Requirements of a blob store

medium 24 min

Before 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

Our systemClientAPI gatewayMetadatano entryStorage zone 1emptyStorage zone 2emptyStorage zone 3empty

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

Our systemClientAPI gatewayMetadataphotosStorage zone 1bytes safeStorage zone 2bytes safeStorage zone 3bytes safe

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

    critical

    A crash after the answer loses a file the user believes is stored.

    Wrong
    reply(200)write_to_zones(data)
    Right
    write_to_zones(data)metadata.commit(key)reply(200)
  • One word for two promises

    major

    An available store can lose data, and a durable store can be unreachable.

    Wrong
    slo = {"reliable": "99.99%"}
    Right
    slo = {"durability": "11 nines",       "availability": "99.99%"}
  • Fixed part size

    major

    8 MB parts stop at 80 GB because of the 10,000 part limit.

    Wrong
    part = 8 * MB
    Right
    part = max(8 * MB, ceil(size / 10_000))
  • Reading one page of a listing

    minor

    A listing returns at most 1,000 keys on S3. The rest is silently missed.

    Wrong
    keys = list(bucket)
    Right
    while 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.