Bifalgorithm post

Let's design Instagram. At first it sounds simple. A user uploads a photo. Other people see it in their feed, like it, comment, share it. But at Instagram scale, every one of those actions becomes a distributed systems problem. When you post a photo or Reel, the media doesn't go into a database, it goes into object storage. The database only stores metadata, who posted it, the caption, and where the media lives. For videos, Instagram also has to transcode different resolutions, bit rates, formats, thumbnails, then delivery. If millions of people watch the same Reel, you don't want every request hitting one storage server. So media sits behind a CDN. Popular photos and video chunks cache closer to users, faster loads, and the origin is protected. Now the feed where it gets much harder. Instagram can't just show every post from everyone you follow in chronological order. It has to decide what's most likely to keep you watching. So the system starts with candidates, people you follow, recommended posts, reels, ads, then ranking models score them using signals like who you interact with, what you watch, what you skip, and how recent it is. The highest ranked content becomes your feed. And this has to happen in milliseconds. Now imagine Cristiano Ronaldo posts a photo. Hundreds of millions of people follow him. Copying that post into hundreds of millions of individual feed records would be extremely expensive. So big accounts get pulled dynamically when followers open the app. Smaller accounts use fanout on right. The post gets pushed into feeds ahead of time. Now likes and views. A reel gets 10 million views in an hour. You don't want 10 million requests fighting over the same database row. So those interactions get written as events. Workers aggregate them asynchronously and update the visible counters periodically. Stories expire after 24 hours, so the system has to drop them from active feeds without scanning the whole database. Notifications work the same way. The person liking your photo shouldn't wait while Instagram sends you a push. And DMs are almost another product. Persistent connections, read receipts, typing indicators, group chats, all in real time. So Instagram is really several systems working together. Object storage holds the media. CDNs distribute it. Databases store users' posts and relationships. Ranking decides what you see. Event pipelines absorb likes and views. Real-time systems handle messaging. The hard part isn't uploading a photo, it's deciding which piece of content out of billions should appear on your screen next and delivering it before you have time to scroll.

Let's design Instagram. At first it sounds simple. A user uploads a photo. Other people see it in their feed, like it, comment, share it. But at Instagram scal…

Ideas in this flowchart

  • Instagram System Design
  • Media Management
  • User Actions
  • Feed Generation
  • Real-Time Features
  • Photo/Video Upload
  • Object Storage
  • Metadata Storage
  • Transcoding Videos
  • CDN Usage
  • User Interactions
  • Event Pipelines
  • Feed Ranking
  • Content Candidates
  • Ranking Models
  • Dynamic Content Loading
  • Fanout on Write
  • Likes and Views
  • Stories Expiration
  • Notifications
  • Direct Messaging
Feed/

Let's design Instagram. At first it sounds simple. A user uploads a photo. Other people see it in their feed, like it, comment, share it. But at Instagram scale, every one of those actions becomes a distributed systems problem. When you post a photo or Reel, the media doesn't go into a database, it goes into object storage. The database only stores metadata, who posted it, the caption, and where the media lives. For videos, Instagram also has to transcode different resolutions, bit rates, formats, thumbnails, then delivery. If millions of people watch the same Reel, you don't want every request hitting one storage server. So media sits behind a CDN. Popular photos and video chunks cache closer to users, faster loads, and the origin is protected. Now the feed where it gets much harder. Instagram can't just show every post from everyone you follow in chronological order. It has to decide what's most likely to keep you watching. So the system starts with candidates, people you follow, recommended posts, reels, ads, then ranking models score them using signals like who you interact with, what you watch, what you skip, and how recent it is. The highest ranked content becomes your feed. And this has to happen in milliseconds. Now imagine Cristiano Ronaldo posts a photo. Hundreds of millions of people follow him. Copying that post into hundreds of millions of individual feed records would be extremely expensive. So big accounts get pulled dynamically when followers open the app. Smaller accounts use fanout on right. The post gets pushed into feeds ahead of time. Now likes and views. A reel gets 10 million views in an hour. You don't want 10 million requests fighting over the same database row. So those interactions get written as events. Workers aggregate them asynchronously and update the visible counters periodically. Stories expire after 24 hours, so the system has to drop them from active feeds without scanning the whole database. Notifications work the same way. The person liking your photo shouldn't wait while Instagram sends you a push. And DMs are almost another product. Persistent connections, read receipts, typing indicators, group chats, all in real time. So Instagram is really several systems working together. Object storage holds the media. CDNs distribute it. Databases store users' posts and relationships. Ranking decides what you see. Event pipelines absorb likes and views. Real-time systems handle messaging. The hard part isn't uploading a photo, it's deciding which piece of content out of billions should appear on your screen next and delivering it before you have time to scroll.

"Let's design Instagram"

👍
0
0 comments0 shares

Sign in to view and post comments.