Prepin
Log in

Create an app that tracks customers' listening history after they have played a song for more than 30 seconds. We aim to utilize this data for analytical purposes.

Approach / Explanation

This inquiry prompts you to create a system for an application that tracks and saves the user's listening history once they have listened to a song for over 30 seconds. The gathered data should be available for analysis. To address this inquiry, you should take into account the following essential points: User and session identification: It is necessary to monitor which user is listening to which song, and you may also need to record session details. Listening duration tracking: A feature is required to log the amount of time a user listens to a specific song. History storage: There must be a method to store this logged information in a database. Data retrieval: The system should be capable of accessing this data for analytical purposes.

Suggested Answer

Initially, we will need to assign distinct identifiers to each user in the app, as well as a method for identifying each individual session they have. To track listening duration, we can set up an event listener that initiates a timer when a song begins playing and halts it when the song is paused, stopped, or when a new song starts. If the timer indicates that the user has listened to a song for 30 seconds or more, an event will be triggered to log this information. For our database, we could utilize a relational database where each row corresponds to a user's song listening instance. The columns could include User ID, Session ID, Song ID, Start Time, End Time, and Total Listening Duration. To analyze this data, we will implement a data retrieval system capable of fetching records based on the specified User ID, Session ID, or Song ID. This will enable the analytics team to easily access and examine the listening history.

Alternative Answer

To begin with, it is essential to uniquely identify each user and track their sessions to associate data with individual users and specific sessions. For monitoring the duration a user spends listening to a song, an event system can be established. When a user plays a song, an event is activated, and the system begins timing. The timer will pause when the song is either paused, stopped, or replaced by another song. A NoSQL database could be utilized for data storage, where each document signifies a unique instance of a song being played for over 30 seconds. Each document would include fields such as User ID, Session ID, Song ID, Timestamp, and Duration Listened. APIs can be developed to enable analytics teams to request data on particular users, sessions, or songs as needed, ensuring that our data collection is both efficient and suitable for thorough analysis.

Question Details

Difficulty & Category

Medium
system design

Companies

Amazon

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.