Design Instagram
Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2021-04-14
Problem Statement
Design a photo & video sharing social media platform (like Instagram) where users can create accounts, upload media, follow other users, and interact via likes, comments, and feeds. The system should support hundreds of millions of daily active users and deliver a real-time, personalized feed at scale.
✅ Functional Requirements
1.<span></span>User Management
2.<span></span>Sign up, login, profile creation, follow/unfollow.
3.<span></span>Content Upload & Storage
4.<span></span>Users can upload photos & short videos.
5.<span></span>Apply compression, thumbnail generation, and store in scalable storage.
6.<span></span>Feed Generation
7.<span></span>Show a user’s feed based on followed accounts + ranking algorithm.
8.<span></span>Support infinite scrolling with pagination.
9.<span></span>Interactions
10.<span></span>Likes, comments, shares, tagging, notifications.
11.<span></span>Search & Discovery
12.<span></span>Search users, hashtags, explore trending posts.
13.<span></span>Stories & Reels (optional extension)
14.<span></span>Ephemeral content that disappears after 24 hours.
⚙️ Non-Functional Requirements
1.<span></span>High Availability → No downtime for critical features.
2.<span></span>Scalability → Handle billions of reads (feed views) and millions of writes (uploads/likes) per day.
3.<span></span>Low Latency → Feed should load in < 200ms.
4.<span></span>Reliability & Durability → Media should never be lost.
5.<span></span>Consistency → Likes/comments should eventually appear in feeds.
6.<span></span>Security & Privacy → Handle access control, private profiles, and secure storage.
🔐 Constraints
1.<span></span>Media files are large and bandwidth heavy → need CDN for fast delivery.
2.<span></span>Feed is read-heavy (10x+ reads vs writes).
3.<span></span>Must support real-time notifications (likes, comments, follows).
4.<span></span>Multi-device support (mobile, web).
🧱 Key Components to Design
1.<span></span>API Gateway – Expose REST/GraphQL APIs to clients.
2.<span></span>User Service – Handles profiles, authentication, relationships (follows).
3.<span></span>Media Service – Upload, compression, metadata storage, CDN distribution.
4.<span></span>Feed Service – Generate and serve personalized feeds.
5.<span></span>Interaction Service – Likes, comments, shares.
6.<span></span>Search Service – User search, hashtag indexing, trending.
7.<span></span>Notification Service – Real-time push notifications & in-app alerts.
8.<span></span>Caching Layer – Speed up feed delivery & profile lookups (Redis, Memcached).
9.<span></span>Database Layer – SQL for metadata, NoSQL for scalable content storage.
10.<span></span>Monitoring & Analytics – Engagement metrics, fraud detection, abuse prevention.
🧪 Example Flow: User Uploads a Photo
<div><div><br /></div><div>1. User uploads a photo from mobile app. </div><div>2. Media Service compresses + stores photo in object storage (S3-like). </div><div>3. Metadata (caption, hashtags, location) stored in DB. </div><div>4. Feed Service updates followers’ feed caches asynchronously. </div><div>5. CDN caches and delivers photo globally. </div><div>6. Followers see new post in their feed in near real-time. </div><div>7. Notification Service pushes alerts to followers. </div></div>👉 This is a classic HLD system design problem that tests:
1.<span></span>Scalability trade-offs (push vs pull for feed, caching strategies).
2.<span></span>Storage design (media storage + metadata DB).
3.<span></span>Real-time systems (notifications, feed freshness).
4.<span></span>CDN, caching, sharding, eventual consistency.