← Lessons

quiz vs the machine

Gold1400

System Design

Design Instagram Photo Sharing

Upload, store, and serve photos with feeds and low latency global delivery.

6 min read · core · beat Gold to climb

Requirements

  • Upload a photo with a caption and metadata.
  • View a feed of photos from followed accounts.
  • Serve images quickly to a global audience.

High level design

Separate the small structured metadata from the large binary image data.

  • Upload path: the client gets a presigned URL and uploads the image directly to object storage, bypassing the app servers.
  • Metadata: post id, owner, caption, and the storage key live in a database, sharded by user id.
  • Delivery: images are served through a CDN, with multiple resized variants generated on upload.

Bottlenecks

  • Image bandwidth: serving full resolution images everywhere is expensive, so precompute thumbnails and feed sized variants.
  • Feed generation: reuse a timeline fanout approach for the photo feed.
  • Hot content: viral posts are absorbed by the CDN edge cache.

Tradeoffs

  • Direct to storage uploads reduce app server load but require careful presigned URL scoping.
  • Precomputing many variants costs storage but saves repeated on the fly resizing.

Key idea

Photo sharing splits tiny metadata in a sharded database from large binaries in object storage fronted by a CDN, with resized variants generated once on upload.

Check yourself

Answer to earn rating on the learn ladder.

1. Why upload images directly to object storage with a presigned URL?

2. Why generate resized variants on upload?