Google Cloud Storage
medium 27 minCloud 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
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 Standard | Days Coldline | Coldline billed | |
|---|---|---|---|
| plan | 5 | 20 | 90 |
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
criticalA late retry or a second worker erases newer data without any error.
Wrongblob.upload_from_string(new)Rightblob.upload_from_string( new, if_generation_match=gen)Names that begin with the time
majorAll new writes meet in one range of the sorted index, and a new range starts cold.
Wrongname = f"{now}/{i}.json"Rightname = f"{h[:6]}/{now}/{i}.json"Cold class for short-lived data
majorThe minimum storage time is billed anyway.
Wrong# deleted after 10 daysstorage_class = "ARCHIVE"Rightstorage_class = "STANDARD"Signed URLs that live for days
majorAnyone who finds the link can use it, and single links cannot be revoked.
Wrongexpiration=timedelta(days=7)Rightexpiration=timedelta(minutes=15)Trusting two regions with everything
minorA wrong delete or a global control failure reaches both. Keep protection that is independent.
Wrong# dual-region = backupRight# 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.