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
Web DevelopmentProgrammingJavaScriptJava EE

Avatar of undefined
Last Comment
David Favor
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
Rohit Bajaj
Flag of India image

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of David Favor
David Favor
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of David Favor
David Favor
Flag of United States of America image

Search - site:github.com php pseudo streaming 206 - for a list of libraries for this.
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo