Social & content · Intermediate

Instagram photo sharing

Early upload, async resizing, sharded PostgreSQL with time-sortable ids and cache-heavy reads.

Every part, and why it is there

Instagram app

Almost all usage is on phones over patchy mobile networks. The app starts uploading the photo while the user is still writing the caption, so pressing “Share” feels instant.

Image CDN

Serves every photo thumbnail and full image from the edge. Photos never change once posted, so they can be cached forever.

Photo storage (S3)

The original upload plus several resized copies per photo. Object storage is the only sensible home for billions of immutable files.

Load balancer

Spreads API calls across a large pool of identical, stateless app servers, so capacity grows by adding servers.

API servers (Django)

Handles posting, liking, commenting and reading the feed. It keeps no state of its own, which is why any server can answer any request.

Upload service

Receives the raw photo bytes, stores the original and queues a processing job. It is separate from the API so large, slow uploads never tie up servers that answer quick feed requests.

Media jobs

Decouples receiving a photo from processing it. Spikes (New Year’s Eve) pile up here instead of timing out the upload.

Resize workers

Produce the thumbnail and display sizes and strip metadata. CPU-heavy work that scales independently of the API.

Memcached

Caches users, posts and counts in front of the database. Most profile and post reads never reach PostgreSQL.

Sharded PostgreSQL

Users, photos, likes and comments, split by user id into thousands of logical shards that live on a smaller number of physical servers. Moving a logical shard to a new machine is how capacity is added without re-sharding.

Feed & counters (Redis)

Per-user feed lists of media ids and fast like/comment counters. Counting likes with a SQL COUNT on every view would melt the database.

Activity events

Every like, comment and follow is published here so notifications, feed fan-out and analytics can react without slowing the request.

Notification service

Turns activity into “X liked your photo” pushes, batching bursts so a viral post does not send a thousand separate alerts.

APNs / FCM

Apple and Google deliver the push to the phone. Instagram cannot reach a sleeping phone any other way.

Asked in interviews at

  • meta
  • doordash
  • uber
  • roblox
  • oracle
  • amazon

Learn more

All system design examples