System Design Playbook
08 · System designs100 users → 100M+ users15 min read

Design Instagram (and how TikTok differs)

Upload photos and videos, follow people and scroll a feed that loads instantly. The classic problem is building the feed: compute it when people open the app, or when someone posts? Plus how TikTok's interest-based feed changes the design.

In one sentence

Instagram's feed is mostly precomputed on write (fan-out to followers), with celebrities merged on read; TikTok's For You feed is recommendation-first: candidates come from what you might like, not from who you follow.

A reference design: it covers what an app like this needs and follows how these companies have described their systems publicly, simplified to be learnable.

Requirements

Functional

  • Post photos and videos
  • Follow accounts
  • Home feed, likes, comments
  • Explore / Reels recommendations

Non-functional

  • Feed loads in ~200 ms
  • Read-heavy: feed reads ≫ posts
  • Media is most of the storage and traffic
  • Eventual consistency is fine (a post can appear a few seconds later)

Back-of-the-envelope estimates

MetricEstimate
Daily users500M, opening the feed ~10 times → ~60K feed reads/s
New posts~100M / day ≈ 1,200 posts/s
Fan-outavg 200 followers → 240K feed inserts/s
Media100M × ~2 MB (all sizes) ≈ 200 TB / day

API and data model

POST /posts         { caption, mediaCount } → { postId, uploadUrls }
GET  /feed?cursor=…                         → [ post ]
POST /posts/:id/like
POST /users/:id/follow

users(id, …)   posts(id, author_id, caption, media, created_at)
follows(follower_id, followee_id)           -- both directions indexed
feed:{user_id} → [post_id, …]               -- Redis list, precomputed

Architecture

Architecture
Scale
Follow a request
◱Appposts, scrolls◍CDNphotos & videos⇄API gateway⚙Post service⚙Feed service⚙Social graphfollows↻Media pipelineresize / transcode↻Fan-out workersqueue-driven⚙Ranking (ML)▣Object storageoriginal media⛁PostgreSQLusers, posts, followsϟRedisfeeds, counters

Step by step · Post a photo

  1. 01Shares a photo
  2. 02POST /posts
  3. 03Creates the post and an upload URL
  4. 04Original uploaded
  5. 05Resized to 3 sizes + thumbnail
  6. 06Post row saved
  7. 07Post id pushed to each follower's feed
  8. 08LPUSH feed:{follower} postId (trimmed to 500)

At this scale · 1M users

Precompute feeds (fan-out on write)

  • ▸When someone posts, workers push the post id into each follower's feed list
  • ▸Opening the feed is reading one list from Redis
  • ▸An ML model re-ranks the feed by interest, not only by time

Tap any box to see what it does.

Deep dive: fan-out on write vs on read

Fan-out on read (pull)Fan-out on write (push)
When the work happensWhen you open the feedWhen someone posts
Feed read costQuery all followees' recent posts and merge: slowRead one precomputed list: fast
Post costCheapOne write per follower: 300M for a celebrity
Good forSmall apps, celebritiesNormal accounts in a read-heavy app

Real systems are hybrid: fan-out on write for normal users, and for accounts with millions of followers, followers pull those posts at read time and merge them into the precomputed list. The merged result goes through a ranking model.

How TikTok differs

Instagram home feedTikTok For You
Where posts come fromAccounts you follow (social graph)Any creator: what the model thinks you'll watch (interest graph)
Main mechanismFan-out + rankingCandidate retrieval + ranking, retrained continuously on your watch time
Key signalWho you interact withWatch time, rewatches, skips in the first seconds
New usersEmpty until they follow peopleUseful from the first swipe (cold start with popular content)
MediaPhotos and videosShort videos only: aggressive prefetching of the next ones

In a TikTok-style design there's no fan-out: a candidate generation step pulls a few thousand videos from many sources (similar to what you watched, trending in your region, new creators), a ranking model scores them, and the app prefetches the next videos so swiping is instant. Instagram's Reels and Explore work the same way.

How it changes with scale

Architecture
Scale
Follow a request
◱Appposts, scrolls⚙App serverposts + feed▣Object storageoriginal media⛁PostgreSQLusers, posts, follows

Step by step · Open the feed

  1. 01Opens the app
  2. 02SELECT posts of people I follow ORDER BY time LIMIT 20
  3. 03Join of follows and posts (slow with many follows)
  4. 04Feed in ~200 ms

At this scale · 100 users

Feed = a SQL query

  • ▸Users, posts and follows in PostgreSQL; photos in S3
  • ▸Feed built on read: posts from people you follow, newest first

Tap any box to see what it does.

UsersWhat you runWhy it changes
100Monolith + PostgreSQL + S3, feed by SQL queryThe join is instant with few follows
10KCDN, image resizing worker, Redis cacheMedia traffic and repeated reads
1MFan-out on write into Redis feeds, ranking, servicesFeed reads dominate and the query gets slow
100M+Hybrid fan-out, sharded PostgreSQL, recommendation feedsCelebrities, billions of rows, interest-based discovery

Key takeaways

  • 01The feed is the core: decide when to do the work, on write (push) or on read (pull).
  • 02Use a hybrid: push for normal accounts, pull for celebrities, then rank.
  • 03Media goes to object storage and a CDN, in several sizes.
  • 04TikTok-style feeds replace the follow graph with candidate retrieval + ranking on watch behaviour.

Check your understanding

1 of 3

In a social feed like Instagram's, what does fan-out on write mean?