AlgoViz

Amazon S3

medium 30 min

Amazon S3 stores objects, whole files with a key and metadata, in buckets that you reach over HTTP.

See it run

A write over three zones, direct uploads, parts, versions, prefixes and a lifecycle.

Operations

PUT, GET and a lost zone

One object is written, read, and read again while a zone is down.

Step 1 of 5

Check

Amazon S3, one regionOur appFront endPUT, signedNamespaceZone A drivesZone B drivesZone C drives

The front end checks the signature and every policy. A deny anywhere ends it.

Step 1: Check

def put(key, data):    check(signature, policies)    store_redundantly(data, zones=3)    namespace[key] = places       # now visible    return 200def get(key):    return rebuild(namespace[key])
Extra cost
3 zones
Protects
Lost zone

Durability is about not losing data. Availability is about answering now. Name both.

In the real world

The same amazon s3 doing real jobs. Pick one and step through it.

Two clients change the same small object.

Step 1 of 3

Both read

Client Ahas e1Client Bhas e1S3 settingsETag e1

Same start

A and B read the settings with ETag e1.

Step 1: Both read

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • A public bucket

    critical

    Anyone with the address can read it, and search tools find such buckets.

    Wrong
    Block Public Access: offPrincipal: "*"
    Right
    Block Public Access: ononly the CDN may read
  • The client chooses the key

    critical

    A user can overwrite another user's object.

    Wrong
    presign("PUT", request.body.key)
    Right
    key = f"uploads/{user.id}/{new_id()}"presign("PUT", key, minutes=15)
  • Read, change, write without a condition

    major

    The latest timestamp wins and the other change disappears.

    Wrong
    put("settings", new)
    Right
    put("settings", new, if_match=etag)
  • Millions of tiny objects

    major

    You pay per request, listings are slow, and cold classes bill at least 128 KB or add metadata.

    Wrong
    one object per event
    Right
    batch to files of many megabytesthen compress
  • Forgotten parts and versions

    minor

    They are invisible in a normal listing and stay on the bill.

    Wrong
    no lifecycle rule
    Right
    abort uploads after 7 daysexpire old versions after 30 days

Interview tips

  • How to explain it

    • A key and an object over HTTP.
    • Three zones or more, eleven nines by design.
    • Strongly consistent for each key.
  • Numbers to know

    • 3,500 writes or 11,000 reads per prefix.
    • 50 TB object, 5 GB single PUT.
    • About 100 to 200 ms for small objects.
  • Reach for it when

    • There are files in the design.
    • Data is written once and read many times.
    • It must be kept for years.
  • Before launch

    • Private bucket, CDN in front.
    • Versioning and lifecycle rules.
    • A tested restore.