SkillSprout
Chapter 2 · Lesson 8
Intermediate
10 min read

Blob and Object Storage

Overview

Photos, videos, backups and documents are blobs: large, opaque chunks of bytes. Storing them in your main database is a mistake, because it bloats the database, makes backups huge and wastes expensive storage on data you never query. The standard answer is an object store (Amazon S3, Google Cloud Storage, Azure Blob) for the bytes, plus a small database for the metadata that describes them.

This lesson explains the object model, how big files are uploaded in chunks, how storage stays durable cheaply with erasure coding, and the pattern that keeps your servers out of the data path: pre-signed URLs.

Detailed Notes

What is it?

A blob (binary large object) is a file-like piece of data such as an image, video or log archive. An object store is a service that stores blobs and retrieves them by name over HTTP.

  • Bucket. A named container for objects (like a top-level folder).
  • Object. The blob itself plus a key (its name, such as users/42/avatar.jpg) and some metadata. The namespace is flat: the slashes in a key are just characters, not real folders, which is why the store scales to trillions of objects.
  • Operations. PUT an object, GET it (optionally a byte range), DELETE it, LIST by key prefix. You cannot edit part of an object in place; you replace the whole object. Objects are effectively immutable.
  • Durability. Large object stores advertise about "11 nines" (99.999999999%) durability: if you keep 10 million objects, you expect to lose one about every 10,000 years.

Why do we need it?

Compare storing a 2 MB photo in a relational database with an object store.

  • Cost and size. Databases use fast, expensive storage and copy every byte into backups and replicas. Object storage is built for cheap capacity, a fraction of the price per GB.
  • Performance. Streaming a large blob through the database takes up its connections, memory and cache, slowing the queries that matter.
  • Scale. An object store grows to petabytes automatically. A database does not.

So we separate concerns: bytes live in the object store, and the database keeps only the small facts (owner, name, size, where the bytes are, status). Database rows stay tiny and queryable.

text
10M uploads/day x 2 MB          = 20 TB per day
20 TB x 365                     = 7.3 PB per year (1 PB = 1,000 TB)
Upload rate: 10M / 100,000 s    = 100 uploads/s (about 200 MB/s of bandwidth)
Metadata: 10M/day x 300 bytes   = 3 GB per day: tiny, so a normal database is fine

The bytes are 7,000 times larger than the metadata. That ratio is the justification for the split.

How does it work?

Architecture: the metadata database plus the object store

Metadata in a Database, Bytes in an Object Store
Architecture
ControlDataClientbrowser / mobileApp serverauth + metadataMetadata DBfiles, chunksObject storebytes, erasure codedBackground jobsthumbnails, cleanup1 request URL2 pending row3 upload byteson uploadmark ready
Key point. Our servers never carry the file bytes. They only authorise and record.

The client talks to our API only for small metadata calls, and sends the bytes straight to storage.

  • Application server. Checks permissions, creates the metadata record, and issues short-lived permission for the client to talk to the object store.
  • Metadata database. Rows such as file_id, owner, name, size, checksum, status, object_key. Queried, indexed, replicated like any database.
  • Object store. Holds the actual bytes.

The crucial pattern: the file bytes should not flow through your application servers. Otherwise, 200 MB/s of upload bandwidth would need dozens of servers just to relay data, and every slow phone connection would hold a server connection open.

Pre-signed URLs

A pre-signed URL is a temporary link to the object store that includes a cryptographic signature granting permission to do one thing (for example, PUT the object users/42/photo-91.jpg) for a short time (for example, 15 minutes).

  1. The client asks the app server: "I want to upload photo.jpg (2 MB)".
  2. The server checks the user, creates a metadata row with status = pending, and returns a pre-signed URL.
  3. The client uploads straight to the object store using that URL.
  4. The object store notifies the app (or the client calls "complete"), and the server marks the row status = ready.

Downloads work the same way: the server verifies access and returns a pre-signed GET URL, so private files stay private without proxying bytes. The pending status plus a cleanup job for old pending rows handles abandoned uploads.

Chunking: uploading big files reliably

A single PUT of a 4 GB video is fragile: one dropped connection restarts everything. Chunking (the object stores call it multipart upload) splits a file into parts that are uploaded independently.

text
File: 1 GB. Chunk size: 5 MB.
Chunks: 1,000 MB / 5 MB = 200 chunks
Connection drops after 120 chunks: resume with the remaining 80 (not 200)
Upload 4 chunks in parallel: roughly 4x faster, limited by the client's bandwidth
Resumable Chunked Upload with Pre-signed URLs
Request flow
ClientApp serverObject store1init upload (1 GB)server creates pending row2200 pre-signed part URLs5 MB chunks, valid 1 hour3PUT chunks 1..1204 in parallel, each with a checksum4connection drops5which chunks arrived?6have 1..1207PUT chunks 121..2008completeserver stitches parts, sets ready
Key point. Chunking turns one fragile 1 GB upload into 200 small retryable ones.

The connection drops after some chunks. The client asks what arrived and sends only the rest.

Details worth stating:

  • Chunk size trade-off. Small chunks (1 MB) recover cheaply from failures but create many requests and a large chunk list. Large chunks (100 MB) mean fewer requests but expensive retries. 5-16 MB is a common range.
  • Checksums. Each chunk is sent with a hash (for example SHA-256) so the server detects corruption. The final file gets a combined checksum.
  • Resumable. The server tracks which chunks arrived. A returning client asks "which do you have?" and sends only the rest.
  • Deduplication. If chunks are identified by their content hash, a chunk already stored (by anyone) need not be stored again. This is called content-addressed storage and is used by file-sync and backup systems. It saves space but costs hashing work and raises privacy questions across users.
  • Assembly. On completion, the store stitches the parts into one logical object, or the metadata keeps an ordered list of chunk ids.
Metadata Tables for Files and Chunks
Data model
filesMetadata DB
  • PKfile_idbigint

    snowflake id

  • IDXowner_idbigint

    list my files; shard key

  • namevarchar(255)
  • size_bytesbigint
  • statusvarchar(12)

    pending / ready / deleted

One row per file, about 300 bytes.

chunksMetadata DB
  • FKfile_idbigint
  • SKchunk_indexint

    order of the chunk

  • IDXchunk_hashchar(64)

    SHA-256, enables dedup

  • object_keyvarchar(128)

    where the bytes live

A 1 GB file with 5 MB chunks has 200 rows.

  • chunks.file_idfiles.file_id· many to one
Key point. The database stores where the bytes are. The object store stores the bytes.

Small rows describe huge objects. The bytes are never stored here.

How the store stays durable cheaply

The object store must not lose data when disks fail, so it keeps redundancy. Two methods:

  • Replication. Keep 3 full copies on different disks and zones. Storage overhead: 3x. Simple, fast reads.
  • Erasure coding. Split an object into, say, 6 data pieces and compute 3 parity pieces (extra pieces from which missing ones can be rebuilt), and store the 9 pieces on 9 different machines. Any 6 of the 9 pieces rebuild the object, so it survives 3 failures. Overhead is 9/6 = 1.5x, half of replication, at the price of CPU for encoding and slower rebuilds.
text
11 PB of raw data needed with 1.5x coding versus 21.9 PB with 3x replication
Saving on 7.3 PB per year of uploads: about 11 PB of disks avoided

Hot, frequently read data often stays replicated for speed, while older data moves to erasure-coded storage tiers: hot (fast, pricey), warm, cold or archive (very cheap, slow or delayed retrieval). A lifecycle rule moves objects automatically, for example "after 30 days, move to cold storage; after 365 days, delete".

Other practical points

  • Consistency. Modern object stores give strong read-after-write consistency for new objects, but the metadata database and the store are two systems, so a failure between them can leave an orphan blob (bytes without a row) or a dangling row (row without bytes). Handle it with the pending status, completion callbacks and periodic reconciliation jobs.
  • Naming keys. Avoid keys that all start with the same prefix if the store partitions by prefix; add a hash prefix to spread load.
  • Access control. Keep buckets private by default; use pre-signed URLs or signed cookies.
  • Large downloads. Support byte ranges (Range header) so video players and download managers can seek and resume.

Interview tip. The classic mistake is storing images as BLOBs in the SQL database, or routing every upload through the app servers. State both rules: "bytes in the object store, metadata in the database; clients upload directly with pre-signed URLs". Also mention what happens when an upload is abandoned.

Real-world example

A photo-sharing app lets users upload up to 10 photos at once. The mobile app asks the server for 10 pre-signed URLs, uploads the photos in parallel directly to the object store, and then calls "complete". The server flips each metadata row from pending to ready and queues background jobs to create thumbnails. A nightly job deletes any row still pending after 24 hours and its partial upload.

System design example

Design file storage for a cloud-drive product where users upload files up to 10 GB.

  • Chunk size 8 MB: a 10 GB file is 10,240 MB / 8 MB = 1,280 chunks. The client uploads 4 at a time and can resume after any failure.
  • Metadata DB tables: files (file_id, owner_id, name, size, status, version) and chunks (file_id, chunk_index, chunk_hash, object_key). Partition by owner_id so listing a user's files hits one shard.
  • Dedup: chunk keys are content hashes, so identical chunks are stored once. 20% duplicate data saves 20% of storage.
  • Durability: erasure-coded storage with 1.5x overhead. 100 PB of user data needs 150 PB raw, versus 300 PB with triple replication.
  • Downloads: pre-signed GET URLs with range support. Frequently accessed files are cached near users.
  • Failure handling: pending rows expire after 24 hours; a reconciliation job compares chunk lists with the object store to find orphans.

Interview discussion. Say: "I'd keep bytes in an object store and only metadata in the database. Clients upload in chunks straight to the store through pre-signed URLs, so our servers handle only small metadata calls. That makes uploads resumable, parallel and cheap to scale."

Trade-off thinking. Object stores give cheap, durable, effectively unlimited capacity, but only whole-object operations and higher latency than a local disk or database. Erasure coding saves space but costs CPU and slower repairs. Chunking adds metadata and complexity, but is required for big or unreliable uploads.

Key interview takeaway

Separate bytes from metadata. Use an object store with pre-signed URLs so clients upload directly, chunk large files for resumability and parallelism, and explain durability (replication vs erasure coding) with numbers. Always cover abandoned uploads and keeping the metadata and the store in sync.

Real World Example

A photo app requests 10 pre-signed URLs, uploads the photos straight to the object store in parallel, then calls "complete". A nightly job removes rows still pending after 24 hours.

Common Interview Questions

Chapter quiz

Data and Storage · 6 questions

  1. 1.Two users try to buy the last item at the same time. Which approach prevents overselling?

  2. 2.A chat app needs the 50 newest messages of a conversation at 10,000 writes per second. Which store fits best?

  3. 3.Which statement about adding database indexes is correct?

  4. 4.With asynchronous replication, a user posts a comment and immediately sees it missing after a reload. What is the best fix?

  5. 5.A cluster uses hash(key) mod N and grows from 4 to 5 nodes. What happens, and what is the better design?

  6. 6.N = 3 replicas, W = 2, R = 2. Which statement is true?

0 of 6 answered

Finished this lesson?

0 of 44 lessons done · 0% of the course