2

I built an iOS app similar to Vine, where a user can scroll a feed of videos that auto play. All of these video have a View_Count field in the backend to keep track of how many times the video has been viewed.

Right now the way I have it set up, is as soon as the user starts watching the video, I increase the View_Count locally on their phone so they can see it tick up, and then I make a call to the backend server with the following steps:

  • Request video object to grab most recent View_Count (the one on the user's phone will be different as many people are watching these videos at the same time)
  • Increase View_Count by 1.
  • Post updated View_Count to server.

I am mostly a front end/iOS guy, so I'm not sure if this is a correct assumption, but I feel like the above steps should NOT be happening on the user's phone. I feel like it is not only using too much of the user's data plan, but also my gut tells me that this type of logic is not supposed to be on the client-side.

Am I correct in assuming this?

All of our video's are stored on AWS using s3 buckets and are being accessed via CDN URL's. I feel like every time an s3/Cloudfront CDN URL is accessed, that AWS should ping my server and increase the View_Count by 1 for that video, but really I have nothing to go off of but my gut instinct because I've never done something like this before.

Am I on the right track at all with these assumptions, or am I approaching this the wrong way?

  • 1
    If I were doing it, I'd update the viewcount on the server when the video is requested, and then include the new value with the video when you display it. Simple. – Robert Harvey Jun 27 '15 at 1:17
  • This won't work because the video object that contains the View_Count field has already been pulled from my server to display in the app, the actual s3/CDN URL is not requested until the user scrolls over it. – user3344977 Jun 27 '15 at 1:26
  • What you are describing seems sensible. Update it on the server each time the client presses play. – GrandmasterB Jun 27 '15 at 5:35
2

The scenario itself: "a user views a video should increase view count" is a client side activity resulting in backend data changes. It is initiated by the user using the client app, so it is okay to put the code that initiates and increases of view count in the client app.

However, here are some other/different ideas to consider:

  1. Keep using the client side code to increase view count, but queue these actions somewhere offline and only sync them periodically.

  2. Proxy the actual URL of the video with a url that redirects to the actual video and increases the view count (completely backend code here)

  3. Use a CDN that can provide the view count statistic out of the box.

And I'm sure there plenty of different ideas out there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.