Design a Music Streaming App
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:
β Functional Requirements
User Management
Music Library
Search
Playback
Playlist Management
Recommendation Engine (optional)
Offline Support (optional)
βοΈ 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
Play Song Flow
Playlist Flow
Download Flow
π 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
π§© Optional Enhancements
π¬ 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.