AlgoViz

Google Cloud Storage

medium 27 min

Cloud Storage is Google Cloud's object store: buckets, immutable objects, strong consistency everywhere, and one API for hot and archived data.

See it run

An upload, a safe overwrite, two regions, cold classes and a hot range.

Operations

Signed upload

A photo goes from a browser to a bucket without passing the app server.

Step 1 of 5

Ask

Our systemBrowserApp serverBucketPub/SubWorker

Valid for 15 minutes

The browser asks the app server, which checks the user and returns a signed URL.

Step 1: Ask

def start(user, name):    check(user)    return sign("PUT", name, minutes=15)def on_finalize(event):    if seen(event.name, event.generation): return    make_small_pictures(event.name)
What you pay
Storage, operations
What you get
No bytes in the app

Give the client a resumable session for large files, so that a break costs one chunk.

In the real world

The same google cloud storage doing real jobs. Pick one and step through it.

A lifecycle rule moves backups to Coldline, and another rule deletes them.

Step 1 of 2

Plan

Days StandardDays ColdlineColdline billed
plan52090

20 used, 90 paid

Coldline after 5 days, delete after 25 days.

Step 1: Plan

Common mistakes

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

  • Writing without a precondition

    critical

    A late retry or a second worker erases newer data without any error.

    Wrong
    blob.upload_from_string(new)
    Right
    blob.upload_from_string(    new, if_generation_match=gen)
  • Names that begin with the time

    major

    All new writes meet in one range of the sorted index, and a new range starts cold.

    Wrong
    name = f"{now}/{i}.json"
    Right
    name = f"{h[:6]}/{now}/{i}.json"
  • Cold class for short-lived data

    major

    The minimum storage time is billed anyway.

    Wrong
    # deleted after 10 daysstorage_class = "ARCHIVE"
    Right
    storage_class = "STANDARD"
  • Signed URLs that live for days

    major

    Anyone who finds the link can use it, and single links cannot be revoked.

    Wrong
    expiration=timedelta(days=7)
    Right
    expiration=timedelta(minutes=15)
  • Trusting two regions with everything

    minor

    A wrong delete or a global control failure reaches both. Keep protection that is independent.

    Wrong
    # dual-region = backup
    Right
    # dual-region + soft delete# + copy in another project

Interview tips

  • How to explain it

    • Immutable objects.
    • A new generation replaces the old in one step.
    • Strong reads and listings.
  • Choosing a class

    • Start from the read rate.
    • Check the minimum days.
    • Unknown pattern: Autoclass.
  • Before a launch

    • Hash in the names.
    • Ramp in the plan.
    • Backoff on 429 and 5xx.
  • Before production

    • Uniform access, no public access.
    • Soft delete chosen on purpose.
    • A restore that was tested.