Design search functionality for music app.
Search for songs, albums, artists, playlists, and podcasts by entering keywords or phrases in the search bar.
FR
1. Users should be able to search for songs, albums, artists, playlists, and podcasts by entering keywords or phrases in the search bar.
2.User should be able to search with song title or artist name.
3.As users type in the search box, they should see real-time suggestions and auto-completions to improve the search experience.
4. Users should be able to refine their search results using filters such as genre, release year, popularity, duration, etc.
5.Should suggest popular and trending searches based on user demographics or global trends.
6.search functionality should allow users to access their search history or quickly find recently played content.
7.create playlist per user based in previous songs played or searched.
8.recommend songs based on history
9.stream music based on search
NFR
1.User must be able to search and get results in real time ,enforcing low latency.
2.Highly available
3.Hihgly Scalable
4.Eventual consistent system
Back Of Envelope Calculation
Number of users=1B
DAU=10% of 1B=10^9*10/100=10^8
Number of searches made by user each day =10 searches /day
total number of searches=10^8*10 searches /day=5*10^8
QPS=10*10^8/10^5=10k QPS
for peak we can 10X5kQPS=100K Qps
API’s
1. GET /search?query=beatles&type=song&limit=10&offset=0&filters[genre]=rock&sortBy=popularity
response
{
"results": [
{
"type": "song",
"id": "12345",
"title": "Hey Jude",
"artist": "The Beatles",
"album": "The Beatles 1",
"duration": 420,
"popularity": 98,
"genre": "Rock",
"releaseYear": 1968
},
...
],
"totalResults": 1000,
"nextPage": "/search?query=beatles&type=song&limit=10&offset=10"
}
DataBase Models
Songs table
{
song_id,(PK)
song_name,
album_id,(FK)
duration,
release_date,
genre_id,
language,
popularity,
photo_image_url,
song_url,
description(text),
}
Artist Table
{ artist_id,(PK) artist_name, popularity, image_url }
3. Album Table
{ album_id, title, artist_id, release_date, genre_id, popularity, cover_image_url }
Playlist table
{ playlist_id, playlist_name, popularity, creator_id, created_at, cover_image_url }
4. user table
{ user_id, user_name, email, hashed_pass created_at }
5. User Search table
{ user id, search_query,(text) search_date }
HLD
Couple of open ended questions
what if old song is deleted from kafka and not in elastic search how to handle it?
should we directly upload to blob storage?