Design Instagram
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2022-08-27
Problem Statement
Designing the Low-Level Design of Instagram, a social media platform for sharing images and videos. The system should allow users to upload, view, like, comment, and follow others while supporting scalability, personalization, and real-time updates.
Functional Requirements (FR)
User Management
•Users can sign up/login.
•Maintain profile (username, bio, profile picture, followers/following).
•Follow/unfollow other users.
Post Management
•Users can upload posts (images/videos) with captions, location, and hashtags.
•Posts can be edited or deleted.
•Users can like or comment on posts.
Feed & Timeline
•Users see a personalized feed of posts from people they follow.
•Feed may be chronologically sorted or algorithmically ranked.
•Support infinite scrolling/pagination.
Stories & Reels
•Users can post stories that expire after 24 hours.
•Reels/videos with autoplay features and recommendations.
Interactions
•Like, comment, save/bookmark, and share posts.
•Tag users or locations.
•Notifications for likes, comments, follows, mentions.
Search & Discovery
•Search by username, hashtags, locations.
•Suggested content based on interests, trends, and activity.
Messaging
•Optional: Direct messaging between users.
Non-Functional Requirements (NFR)
•Scalability: Support millions of users and posts.
•Performance: Low latency for feed retrieval, post upload, and interactions.
•Availability: 24/7 uptime.
•Consistency: Likes/comments should be accurate and reflected in real-time.
•Storage Efficiency: Optimize for media storage and retrieval.
Core Entities & Attributes
User
•userId, username, email, password, profilePic, followers[], following[], posts[]
Post
•postId, userId, mediaUrl, caption, timestamp, likesCount, comments[], tags[]
Comment
•commentId, postId, userId, content, timestamp
Like
•likeId, postId, userId, timestamp
Story
•storyId, userId, mediaUrl, timestamp, expirationTime
Feed
•userId, listOfPosts (ordered by relevance/recency)
Notification
•notificationId, recipientId, type (like/comment/follow), sourceUserId, timestamp
APIs / Operations
User APIs
•createUser(name, email, password)
•followUser(followerId, followeeId)
•getUserProfile(userId)
Post APIs
•createPost(userId, mediaUrl, caption, tags)
•likePost(userId, postId)
•commentPost(userId, postId, content)
•getPost(postId)
Feed APIs
•getFeed(userId, page, limit)
•getStories(userId)
Search APIs
•searchUsers(keyword)
•searchPostsByTag(tag)
Advanced Features (Optional / Bonus)
•Content recommendation using ML for personalized feed.
•Hashtag and trend analytics.
•Video streaming optimizations (CDN, caching).
•Offline support and prefetching posts.
•Multiple media uploads per post (carousel).
•AI-based content moderation (detect inappropriate content).