Design a Social Networking Site

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-03-29

Problem Statement

Designing the core classes and services of a social networking platform. Focus on object-oriented design, class interactions, and service responsibilities rather than distributed system scaling.


Requirements


Functional


1.User Management
•Users can register, log in, and manage profiles.
•Support for user connections (friend requests / follow/unfollow).
2.Posts & Content
•Users can create, edit, delete posts (text, images, videos).
•Like, comment, and share posts.
3.News Feed / Timeline
•Display posts from friends/followed users in chronological or relevance order.
•Support basic filtering (most recent, trending).
4.Notifications
•Notify users about likes, comments, new followers, or mentions.
5.Messaging
•One-to-one chat (optional for LLD).
•Track read/unread status.
6.Search
•Search users, posts, or hashtags.


Non-Functional


•Extensibility – Easy to add new content types or reactions.
•Thread Safety – Handle concurrent likes, comments, and posts.
•Performance – Efficient retrieval of posts and notifications.
•Consistency – Ensure likes, comments, and friend connections are updated atomically.


Expectations from the Candidate


•Class Diagram
•Entities like User, Post, Comment, Like, Notification, FriendRequest.
•Relationships (associations, aggregation, inheritance).
•Service Layer Design
•Services such as UserService, PostService, FeedService, NotificationService, MessagingService.
•Each service handles business logic, validations, and interactions between entities.
•Design Patterns
•Observer pattern for notifications.
•Singleton for system-wide managers (e.g., NotificationManager).
•Factory pattern for different post types (text, image, video).
•Trade-offs & Considerations
•Concurrency in likes/comments.
•Efficient feed generation (real-time vs batch).
•Extensibility for reactions, stories, or multimedia content.


✅ This LLD problem tests:


•OOP and class design skills.
•Ability to model social interactions and content structures.
•Understanding of services, relationships, and design patterns.


Solution

Comments