Design a Music Streaming App

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-06-06

Problem Statement

Designing the low-level architecture of a Music Streaming App (like Spotify, Apple Music, or Gaana) that allows users to search, play, and manage songs from a large music library.

The system should support both online streaming and offline playback, with playlists, user accounts, and song metadata.


🎯 Problem Statement


Design the classes, interactions, and data models for a Music Streaming Application that supports:


β€’Managing songs, artists, and albums
β€’User account and playlist creation
β€’Playing songs (online or offline)
β€’Searching songs by title, artist, or genre


βœ… Functional Requirements


User Management

β€’Users can register, log in, and manage their accounts.
β€’Each user can create and manage multiple playlists.

Music Library

β€’Songs are categorized by title, artist, album, and genre.
β€’Each song has metadata: duration, release date, likes, etc.

Search

β€’Users can search songs, artists, or albums by keyword.
β€’Return relevant results efficiently.

Playback

β€’Users can play, pause, skip, or replay songs.
β€’App should support both online streaming and offline downloaded songs.

Playlist Management

β€’Users can add/remove songs from playlists.
β€’Create public/private playlists.

Recommendation Engine (optional)

β€’Suggest songs or playlists based on user history.

Offline Support (optional)

β€’Allow users to download songs for offline playback.


βš™οΈ Non-Functional Requirements

Aspect with Description


Performance

Fast search and minimal playback latency


Scalability

Should handle thousands of songs per user


Availability

Works offline for downloaded songs


Extensibility

Easy to add new features like podcasts or lyrics


Maintainability

Clean modular class design


🧱 Core Entities / Classes


1. User


Represents a user profile with playlists and preferences.

1 2class User { 3 String userId; 4 String name; 5 List<Playlist> playlists; 6 Library library; 7 8 void createPlaylist(String name); 9 void deletePlaylist(String playlistId); 10 void addSongToPlaylist(String playlistId, Song song); 11}


2. Song


Encapsulates metadata of each song.

1 2class Song { 3 String songId; 4 String title; 5 Artist artist; 6 Album album; 7 Genre genre; 8 Duration duration; 9 int likes; 10 String url; // streaming URL 11 12 void play(); 13}


3. Artist / Album


Represents song creators and collections.

1 2class Artist { 3 String artistId; 4 String name; 5 List<Album> albums; 6} 7 8class Album { 9 String albumId; 10 String title; 11 Artist artist; 12 List<Song> songs; 13}


4. Playlist


Stores a user’s collection of songs.

1 2class Playlist { 3 String playlistId; 4 String name; 5 List<Song> songs; 6 7 void addSong(Song song); 8 void removeSong(Song song); 9}


5. Player


Controls playback functions.

1 2class Player { 3 Song currentSong; 4 PlayerState state; // PLAYING, PAUSED, STOPPED 5 6 void play(Song song); 7 void pause(); 8 void resume(); 9 void next(Song nextSong); 10}


6. MusicLibrary


Holds all available songs and provides search capability.

1 2class MusicLibrary { 3 Map<String, Song> songs; 4 Map<String, Artist> artists; 5 6 List<Song> search(String query); 7}


7. DownloadManager (optional)


Handles offline downloads.

1 2class DownloadManager { 3 void downloadSong(Song song); 4 boolean isDownloaded(Song song); 5}


8. RecommendationEngine (optional)


Suggests songs based on user behavior.

1 2class RecommendationEngine { 3 List<Song> recommend(User user); 4}


🧠 Key Design Interactions

Search Flow

β€’User enters query β†’ MusicLibrary.search(query) β†’ returns list of songs/artists.

Play Song Flow

β€’User selects a song β†’ Player.play(song) β†’ fetch stream/download β†’ plays audio.

Playlist Flow

β€’User creates a playlist β†’ adds/removes songs via Playlist methods.

Download Flow

β€’User chooses to download β†’ DownloadManager.downloadSong(song) β†’ stores offline file.


πŸ” Class Relationships (UML Overview)

1 2User 3 β”œβ”€β”€ Library 4 β”‚ └── List<Song> 5 β”œβ”€β”€ List<Playlist> 6 └── Player 7 8Playlist ── contains ──> Song 9Song ── belongs to ──> Album ── by ──> Artist 10Player ── plays ──> Song 11MusicLibrary ── contains ──> Song, Artist, Album


πŸ“¦ Design Goals


β€’Encapsulation: Keep playback, search, and user management independent.
β€’Reusability: Classes like Song, Artist, and Player can be reused across mobile/web.
β€’Extensibility: Easily add podcasts, radio channels, or recommendations.


🧩 Optional Enhancements


β€’Add Queue or Shuffle support in Player.
β€’Introduce Song Analytics (play count, skip count).
β€’Add Lyrics API integration.
β€’Include premium/free user roles for feature access control.


πŸ’¬ Interview Prompt (Final Form)

Design a Music Streaming Application (like Spotify or Apple Music).
The system should allow users to create playlists, search songs, play music (online/offline), and manage their libraries.
Explain your class design, relationships, and interactions between major components like User, Song, Playlist, and Player.


Solution

Comments