11. Object / Blob Storage
Practice: five levels
Assignments
Five levels. Do them in order. Answers are in "Solutions" at the end, so try first.
Level 1: Think (no code)
A. Database, object storage, or both? One line each.
- A book's title, price and author.
- The book's cover image.
- A 300 MB author interview video.
- Which user uploaded which review photo, and when.
- Daily database backups kept for a year.
B. True or false? Explain.
- "Object storage has folders, so I can rename the folder
covers/toimages/instantly." - "Eleven nines of durability means I don't need backups."
- "Presigned URLs are safe to give out with a 30-day expiry for paid downloads."
Level 2: Calculate
- The bookstore has 1 million books, each with three cover sizes of 500 KB, 100 KB and 20 KB. How much storage? With 3× replication? With 10 + 4 erasure coding?
- A 5 GB video is uploaded over a 20 Mbps connection. How long does it take? In 100 MB parts, how many parts? If the connection drops at 90%, how much is re-sent with and without multipart?
- Covers get 50 million views a day at 100 KB each. How much data a day leaves storage? What's the average bandwidth in Gbps?
Level 3: Build
In Python (standard library only), build a tiny object store:
put(key, data, content_type, meta),get(key),head(key)(size, type, ETag, your metadata) andlist(prefix).- Multipart:
start_multipart,upload_part(upload_id, n, data)(any order, retries allowed),complete_multipart. presign(method, key, expires_at)using an HMAC signature, andverify(method, url, now).
Check that: listing by prefix works; objects are replaced whole; a presigned URL works before expiry and fails after; changing the method, the key, or the expiry breaks it; multipart parts uploaded out of order (with one retried) produce exactly the original bytes.
Level 4: Debug
Customers have been sharing paid e-book download links on forums, and the links keep working for months, though they were meant to expire in 10 minutes. The code:
- Find the bug. Explain step by step how someone makes a link that works forever.
- Fix it.
- Name one more control you'd add for paid downloads.
Level 5: Design
Design the bookstore's file handling:
- Cover images for 1 million books, shown on every page.
- Paid e-book PDFs (up to 50 MB), downloadable only by buyers.
- Review photos uploaded from phones (up to 15 MB).
- Author videos up to 5 GB.
Deliver:
- Buckets and key layout.
- The upload flow for review photos and for videos.
- How paid PDFs are protected.
- How covers are processed and served.
- Lifecycle rules and one way you'd protect against accidental deletion.