AlgoViz

Object storage

easy 26 min

Object storage keeps files as objects: the bytes, some metadata and a unique key, in a flat bucket reached over HTTP.

See it run

Put a whole object in, get it back by key, send a big one in parts, and let rules move the old ones.

Operations

PUT an object

A photo travels from the client to three zones.

Step 1 of 6

Client request

Our systemClientPUT photoFront endKey indexStorage zone 1Storage zone 2Storage zone 3

images/photo.jpg

An HTTP PUT with the key images/photo.jpg and the bytes.

Step 1: Client request

def put(key, data, who):    check_permission(who, "put", key)    pieces = encode(data)    places = write_to_zones(pieces)    index[key] = (places, metadata)    return etag(data)
Requests
1 request
You pay for
Request and storage
Server disk
lost with the server

The key points to the new content only after the bytes are safe.

In the real world

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

A script deletes the wrong key in a versioned bucket.

Step 1 of 4

Three versions

versiondatesizestate
v11 Jan1.2 MBkept
v25 Jan1.4 MBkept
v310 Jan1.3 MBcurrent

3.9 MB stored

Each PUT made a new version. v3 is current.

Step 1: Three versions

Common mistakes

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

  • Sending files through the API server

    major

    Each upload holds a connection and memory, and every byte is paid twice.

    Wrong
    def upload(request):    bucket.put(key, request.read())
    Right
    def upload_url(request):    return presign("PUT", new_key(), minutes=15)
  • A public bucket

    critical

    Anyone who guesses a key reads the file, and nobody notices.

    Wrong
    policy.allow("*", "get", "*")
    Right
    block_public_access(bucket)serve_with(cdn, signed_urls=True)
  • Taking durability for a backup

    critical

    Eleven nines keep a wrong delete just as safely as a right one.

    Wrong
    bucket.versioning = False     # 11 nines!
    Right
    bucket.versioning = Truecopy_to(other_account, object_lock=True)
  • Using a key as if it were a file

    major

    Appending one line means reading and writing the whole object again, and two writers lose lines.

    Wrong
    old = bucket.get("app.log")bucket.put("app.log", old + line)
    Right
    bucket.put(f"logs/{minute}/{host}.log", lines)

Interview tips

  • How to explain it

    • Key, data and metadata in a flat bucket.
    • Whole objects over HTTP.
    • Very durable, very large, cheap to keep.
  • Memory trick: BLOB

    • Bucket: the container
    • Lifecycle: automatic moves
    • Object: key, data, metadata
    • Billions: it grows very far
  • Reach for it when

    • Files are large and rarely change.
    • Many people download them.
    • You keep backups, logs or archives.
  • Be careful

    • Folders are only prefixes.
    • Cold classes cost time and fees to read.
    • A presigned URL works for anyone who has it.