Social feed (Instagram-style)
Users, follows, posts and likes: a feed model with the Observer pattern for notifications and a strategy for ordering.
On the roadmap:Software Design · step 6: Low-level design: games and apps
Lesson 15 of 16 · 10 min read · quiz · exercise
The problem
Users follow each other, publish photo posts, like and comment, and see a home feed of posts from the accounts they follow. This lesson models the classes and rules. Scaling the feed (fan-out strategies) is covered in the news-feed lesson of the classic designs course.
Entities
Figure SDA-LLD-15-1 · Social feed classes · © forcsguy.com
Publishing and the feed
Figure SDA-LLD-15-2 · Publishing a post · © forcsguy.com
interface FeedStrategy { build(userId: string, limit: number): Post[] }
const newestFirst: FeedStrategy = {
build(userId, limit) {
const followees = follows.acceptedFolloweesOf(userId);
return posts.byAuthors(followees).filter(p => canView(userId, p))
.sort((a, b) => b.createdAt - a.createdAt).slice(0, limit);
},
};
function canView(viewer: string, p: Post): boolean { // one place for visibility rules
const author = users.get(p.authorId);
return !author.isPrivate || author.id === viewer || follows.isAccepted(viewer, author.id);
}
Putting visibility in one function means the feed, profile and search all agree about who may see what.
Likes and comments
- A like is unique per
(user, post); enforce it with a uniqueness rule, not just a check, so double taps do not create two likes. - Keep a like count on the post for fast display and update it with each like or unlike, accepting that the count may briefly lag.
- Comments are ordered by time and can have a parent id for replies.
Design notes
- Pagination uses a cursor (the time or id of the last item) so new posts do not shift pages.
- Deleting a post must remove it from feeds and counts; a soft delete flag filtered at read time is the usual first step.
- Blocking and muting are visibility rules too.
- Extensions: stories with expiry, hashtags, tagging, search, and a ranking strategy that mixes recency with interest.
Real-world reading
Related reading
- Self-Ranking Search with Elasticsearch at WattpadWattpad engineers · WattpadCase Studies
- Monitoring Powers High Availability for LinkedIn FeedUSENIX engineers · USENIXCase Studies
- Search Federation Architecture at LinkedIn (2018)LinkedIn engineers · LinkedInCase Studies
- Scaling the Hadoop Distributed File System at LinkedInLinkedIn engineers · LinkedInCase Studies
Show 6 moreShow fewer
- Galene: Search Architecture of LinkedInLinkedIn engineers · LinkedInCase Studies
- Infrastructure to Run User Forecasts at SpotifySpotify engineers · SpotifyCase Studies
- Scalable User Privacy at SpotifySpotify engineers · SpotifyCase Studies
- Moving Food Feed from Redis to Cassandra at ZomatoZomato engineers · ZomatoCase Studies
- Clustering Similar Stories Using LDA at FlipboardFlipboard engineers · FlipboardCase Studies
- Data Orchestration Service at SpotifySpotify engineers · SpotifyCase Studies
Check your understanding
Question 1 of 3
0 correct so far
How should the home feed be ordered in a first version?
Go deeper
- Design the news feed (classic system designs course) by This site: for fan-out on write versus read at scale
Practise it: Social feed
Everything below is already set up for this lesson: change the design, run the traffic, and see whether you meet the goal.
- 1The task
- 2Build and test
Mixed reads and writes, busy in the evening.
Add or remove parts, move traffic up and down, and break something to see what gives way first.
Try it yourself
Add stories that expire after 24 hours and private accounts that need follow approval. What changes?
Click what a strong design here would need:
More in Design practice
© 2026 forcsguy.com. Original lesson text and diagrams. Books and sites linked above belong to their authors.