💬
✉️
📸
▶️

Loading…

Design Instagram: media upload, CDN, and feed ranking

InstagramGuided Mode

Naïve Start: How Instagram Stored Photos in 2010

Instagram launched in October 2010 and went viral overnight — 25,000 users on day one. Their MVP stored photos as binary blobs directly in the Database. It worked in the hackathon. It broke in production.

Request Flow

1

Client uploads photo

The Poster client sends a POST request with the image bytes in the body. The API receives the full payload — blocking a request thread for the entire transfer duration.

POST /api/photos
Content-Type: multipart/form-data
Body: <2 MB raw bytes>
2

API writes to DB

The API inserts the binary blob into a BYTEA (or BLOB) column in the Database. Row size is now 2MB+. Table scans, backups, and replication all slow down.

INSERT INTO photos (user_id, data, created_at)
VALUES ($1, $2, NOW())
3

Viewer fetches photo

A GET request goes through the API, which queries the Database and streams the raw bytes back. Every photo view = one full DB read.

Why We Need This

Databases are optimised for structured, indexed, transactional data. Storing binary blobs in them causes: row-level bloat slowing all queries, replication lag as 2MB rows are synced, and expensive per-row DB reads for every image view.

Key Insight

Databases are not file systems. A 2 MB image row is 200× larger than a typical user-profile row. Mixing blobs with relational data degrades every operation — backups, vacuums, queries — not just photo reads.

Step 1 of 7