💬
✉️
📸
▶️

Loading…

Design Dropbox: file chunking, sync, and storage

DropboxGuided Mode

Naïve Start: Storing Files in a Database

Imagine storing every uploaded file as a binary blob in a database row. It works for small text files. The moment someone uploads a 500 MB video, the API thread is blocked for minutes, the DB row is huge, and replication grinds to a halt.

Request Flow

1

Device A uploads file

Device A sends a POST request with the full file bytes in the body. The API receives and buffers the entire file in memory.

POST /api/files
Content-Type: application/octet-stream
Body: <500 MB raw bytes>
2

API writes blob to DB

The API inserts the binary blob into a BYTEA column in the Database. A 500 MB file = one 500 MB row. Table scans, backups, and replication all degrade.

INSERT INTO files (user_id, name, data)
VALUES ($1, $2, $3)
3

Device B fetches file

Device B sends a GET request. The API queries the DB, reads the 500 MB row, and streams bytes back. Every download = one full DB read.

Why We Need This

Databases are optimised for small, structured, indexed rows. A 500 MB blob row bloats MVCC buffers, slows every vacuum, delays replication, and makes backups impractical. Mixing blobs with relational data degrades the entire database cluster.

Key Insight

Files are not relational data. Storing them in a DB pollutes your query engine with binary blobs it was never designed to hold.

Step 1 of 8