Design Instagram: media upload, CDN, and feed ranking
Instagram's Fix: Move Photos to S3
Instagram migrated to S3 / Blob Storage within weeks of launch. Instead of storing binary data in the Database, the API streams uploads to S3 and saves only the URL. This is still how Instagram works today.
Request Flow
API streams upload to S3
The API receives the upload and proxies it to S3 / Blob Storage. S3 is purpose-built for large binary objects and costs ~$0.023/GB vs ~$0.10+/GB for database disk.
s3.putObject({
Bucket: 'photos',
Key: `${userId}/${photoId}.jpg`,
Body: imageStream
})Save URL in database
The Database now stores only a short string URL (< 200 bytes) instead of 2MB of binary data. Row size drops by 10,000×. All existing queries stay fast.
INSERT INTO photos(user_id, s3_url, created_at) VALUES ($1, $2, NOW())
Viewer fetches via API→S3
The API still proxies every read through itself, acting as an intermediary between the client and S3 / Blob Storage. Better than DB reads, but all bandwidth passes through the API fleet.
Why We Need This
S3 stores objects on horizontally-scaled, replicated commodity hardware. Read and write throughput scales independently of your API tier. Costs are predictable per-GB/month rather than tied to expensive IOPS.
Key Insight
Object storage is the industry-standard solution for binary data. Every major platform — Instagram, YouTube, Dropbox — separates blob storage from relational data. The database becomes a catalog of URLs, not a file system.
Step 2 of 7
