💬
✉️
📸
▶️

Loading…

Design Instagram: media upload, CDN, and feed ranking

InstagramGuided Mode

Instagram's Feed Service: Photos to 2B Users

Adding the Feed Service closes the loop: when @cristiano posts, Instagram fans that post out to 600M followers' timeline caches. When you open your feed, CDN URLs in your timeline resolve directly to edge-cached photos in milliseconds.

Request Flow

1

Photo upload triggers fanout

After upload completes and metadata is saved to the Database, the API calls the Feed Service to fanout the new post to all followers' timeline caches.

feedService.fanout({
  authorId: userId,
  photoId,
  cdnUrl: 'https://cdn.example.com/photos/...',
  timestamp: now
})
2

Feed Service builds timelines

The Feed Service pushes the post to the timeline cache of each follower. For normal users (< 1M followers), this is a write-time fanout — reads become O(1) cache reads.

3

Viewer reads cached timeline

The Viewer's GET /feed returns a list of CDN URLs. No S3 reads. No heavy DB joins. The timeline is a pre-assembled list of content identifiers pointing to edge-cached images.

GET /feed
→ [
  { url: 'cdn.example.com/photo1_md.jpg', ... },
  { url: 'cdn.example.com/photo2_md.jpg', ... }
]

Why We Need This

Without fanout, every viewer's timeline requires joining follows → posts → photo metadata at read time — an O(followers × recent_posts) query that doesn't scale past thousands of users.

Key Insight

The feed service turns expensive read-time fan-in into cheap write-time fan-out. Combined with CDN image delivery, a viewer's entire feed can be served from cache with zero origin reads.

Step 6 of 7