Design Video Streaming Service

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-04-02

Problem Statement

Low-Level Design (LLD) of a Video Streaming Service that allows users to upload, stream, and manage videos online.


The system should manage video storage, playback, user preferences, and content recommendations, focusing primarily on object modeling, class design, and core feature logic, not on distributed systems or large-scale infrastructure (that belongs in HLD).


🎯 Goal


Design a system that can:


β€’Allow users to upload, view, like, comment, and share videos.
β€’Support video encoding into multiple quality formats (360p, 720p, 1080p).
β€’Allow search and recommendations.
β€’Manage user subscriptions and playlists.
β€’Track view counts and watch history.


βœ… Functional Requirements


1. User Management


β€’Users can:
β€’Register, login, and manage profiles.
β€’Subscribe to channels or follow other users.
β€’Create and manage playlists.


2. Video Management


β€’A User can upload a Video.
β€’Each video has:
β€’Metadata (title, description, tags, upload time, category).
β€’Uploader details.
β€’Duration and video quality formats.
β€’When uploaded:
β€’The video is encoded/transcoded into multiple resolutions.
β€’A thumbnail is generated.
β€’It’s marked as available for streaming after processing.


3. Streaming


β€’Users can watch videos online.
β€’Video player supports:
β€’Play, pause, seek, and change quality.
β€’Adaptive bitrate streaming (auto quality based on bandwidth).
β€’System tracks:
β€’Views
β€’Watch time
β€’Last watched timestamp (for resume feature)


4. Engagement


β€’Users can:
β€’Like / Dislike videos.
β€’Add comments.
β€’Share video links.
β€’System maintains view count, like count, comment threads.


5. Search and Recommendation


β€’Search by title, tags, or uploader.
β€’Recommended videos based on:
β€’Watch history
β€’Similar tags
β€’Subscribed channels


6. Playback History


β€’Maintain each user’s watch history.
β€’Allow β€œContinue Watching” feature.


βš™οΈ Non-Functional Requirements


β€’Scalable design for future expansion.
β€’Thread-safe updates to view counts and likes.
β€’Extensible to support live streaming, ads, or premium content.
β€’Low latency for streaming playback.


🧱 Key Classes to Design


ClassResponsibility


User

Represents a platform user with details, subscriptions, playlists, and history.


Video

Represents a video with metadata, formats, uploader, and stats.


VideoFile

Represents different encodings of a video (360p, 720p, 1080p).


Channel

Represents a user’s content collection (like YouTube channel).


Playlist

Represents a list of user-selected videos.


Comment

Represents user comments on a video (supports threads).


VideoPlayer

Handles playback operations (play, pause, seek).


RecommendationEngine

Suggests videos based on user activity.


SearchService

Enables keyword and tag-based search.


VideoManager

Handles upload, encoding, and metadata updates.


EngagementManager

Manages likes, dislikes, and view counts.


🧩 Example Class Relationships

1 2User 3 β”œβ”€β”€ id 4 β”œβ”€β”€ name 5 β”œβ”€β”€ List<Subscription> 6 β”œβ”€β”€ List<Playlist> 7 β”œβ”€β”€ List<WatchHistory> 8 9Video 10 β”œβ”€β”€ id 11 β”œβ”€β”€ title 12 β”œβ”€β”€ description 13 β”œβ”€β”€ uploader (User) 14 β”œβ”€β”€ List<VideoFile> 15 β”œβ”€β”€ stats (views, likes, comments) 16 β”œβ”€β”€ tags, category 17 18VideoFile 19 β”œβ”€β”€ resolution 20 β”œβ”€β”€ filePath 21 β”œβ”€β”€ format (mp4, webm) 22 23Playlist 24 β”œβ”€β”€ id 25 β”œβ”€β”€ name 26 β”œβ”€β”€ List<Video> 27 28Comment 29 β”œβ”€β”€ id 30 β”œβ”€β”€ text 31 β”œβ”€β”€ user 32 β”œβ”€β”€ timestamp 33 β”œβ”€β”€ replies (List<Comment>)


πŸ”„ Example Flow


🎬 Video Upload Flow


1.User uploads a video file.
2.System stores metadata in DB and uploads raw file to storage.
3.Background job encodes it to multiple resolutions (360p, 720p, etc.).
4.Generates thumbnail and preview.
5.Marks video as available for streaming.


▢️ Video Playback Flow


1.User selects a video.
2.Player requests video chunks based on chosen quality.
3.Video stream is played.
4.On completion:
β€’View count increments.
β€’Watch history is updated.


πŸ§ͺ Example Input / Output


Input:

1 2User: Sahil 3Action: Upload video 4File: intro_to_ds.mp4 5Tags: ["data structures", "tutorial"] 6Category: "Education"


Output:

1 2Video uploaded successfully. 3Video ID: V10293 4Available formats: 360p, 720p, 1080p


Playback Example:

1 2User: Sahil 3Action: Play Video (V10293) at 720p 4Output: Streaming started...


πŸ” Concurrency & Safety


β€’Ensure atomic increment of views and likes.
β€’Lock-free algorithms for counters (to scale under load).
β€’Access control for private/unlisted videos.


🧠 Possible Extensions


β€’Add live streaming.
β€’Add monetization and ads.
β€’Add video analytics dashboard.
β€’Implement content moderation (report, flag, remove).


βœ… Summary:


Design a Video Streaming Service (LLD) that supports:


β€’Uploading, viewing, and engaging with videos,
β€’Multi-quality playback,
β€’Search and recommendation,
β€’User playlists and history tracking.


Focus on object design, metadata management, and core streaming logic β€” not CDN or large-scale architecture.

Solution

Comments