Link to home
Start Free TrialLog in
Avatar of Rohit Bajaj
Rohit BajajFlag for India

asked on

Tracking how many people are currently watching a video.

HI,
The problem is to design a solution for finding the number of users who are watching a particular video eg. on youtube etc.
Here is what i thought about solving it.
If the video is playing than every 5th minute from GMT it will send a play event
I will maintain a table containing  (userId, movieId, timeStamp)
So to count how many viewers playing a video i will simply have to count the number of entries in the table with the movieID and timeStamp not later than 5 minutes. Because if a play event is not recieved for 6 minutes than the video must not be playing...
And each time a play event is received the timeStamp will be updated to the current time.

Also i will run a cronJob that will be clearing entries that are not getting updated.
Will maintain a cache containing the count for each movie and will update it at a regular interval from the table.

Each video that is being played will send a https request for the number of current viewers every 6th minute and the number of viewers will be updated.
Please suggest if there is any flaw in this approach. or any better approach ?
Any pros and cons ?
Thanks
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

If the video is a youtube video you can use the api to get accurate information https://developers.google.com/youtube/analytics/sample-requests
Avatar of Rohit Bajaj

ASKER

No its not about using an api.
The question is for testing ones ability to design such a thing.

Its a challenge question. Nothing to do with any website in particular
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Search - site:github.com php pseudo streaming 206 - for a list of libraries for this.