Object storage
easy 26 minObject 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
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
| version | date | size | state |
|---|---|---|---|
| v1 | 1 Jan | 1.2 MB | kept |
| v2 | 5 Jan | 1.4 MB | kept |
| v3 | 10 Jan | 1.3 MB | current |
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
majorEach upload holds a connection and memory, and every byte is paid twice.
Wrongdef upload(request): bucket.put(key, request.read())Rightdef upload_url(request): return presign("PUT", new_key(), minutes=15)A public bucket
criticalAnyone who guesses a key reads the file, and nobody notices.
Wrongpolicy.allow("*", "get", "*")Rightblock_public_access(bucket)serve_with(cdn, signed_urls=True)Taking durability for a backup
criticalEleven nines keep a wrong delete just as safely as a right one.
Wrongbucket.versioning = False # 11 nines!Rightbucket.versioning = Truecopy_to(other_account, object_lock=True)Using a key as if it were a file
majorAppending one line means reading and writing the whole object again, and two writers lose lines.
Wrongold = bucket.get("app.log")bucket.put("app.log", old + line)Rightbucket.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.