Design Instagram

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-03-15

Problem Statement

Design the Low-Level Design of Instagram, a social media platform where users can share photos/videos, follow other users, like/comment on posts, and receive notifications. The system should be extensible, object-oriented, and optimized for scalability and clean design.


Functional Requirements


1.User Management
•Create account, login/logout.
•Follow/unfollow users.
•View profile, followers, following lists.
2.Content Management
•Upload photo/video posts.
•Add captions, hashtags, tags.
•Support multiple media types (image, video, reel).
•Delete/update posts.
3.Engagement Features
•Like/unlike a post.
•Comment on a post.
•View post insights (likes, comments count).
4.Feed & Timeline
•Show personalized timeline with posts from followed users.
•Support sorting by latest or engagement.
5.Notifications
•Notify users for likes, comments, follows, and mentions.
6.Search & Discovery
•Search users, posts (by hashtags, keywords).
•Explore trending posts.


Non-Functional Requirements


•Extensibility → support stories, reels, ads in future.
•Scalability → large number of users and posts.
•Modularity → well-separated classes (User, Post, Comment, Notification).
•Performance → efficient retrieval of feed.


Design Hints


•Core Classes:
•User (id, name, followers, following).
•Post (id, media, caption, author, likes, comments).
•Comment (id, text, author, timestamp).
•Like (userId, postId, timestamp).
•Notification (type, user, target, timestamp).
•FeedService (fetches posts for user timeline).
•Relationships:
•One User → Many Posts.
•One Post → Many Likes & Comments.
•One User → Many Notifications.
•Patterns:
•Observer Pattern → Notify users of likes/comments.
•Factory/Strategy Pattern → For feed ranking & recommendation strategies.


Solution

Comments