I am new to mobile app development. I am stuck at a problem where I am unable to decide how to build the solution. Please help me.
My issues: I am building a video streaming app similar to instagram, but in my case the call to server from client needs to be reduced. The concern is when user views a video, when should I update the server with metadata? For example : suppose at a given time on the app user viewed sequentially 20 videos and he liked all twenty and commented in all twenty.
Then in this case - I have to update LikesCount, ViewCount and AddComment, this can become atleast 20 API calls, if done realtime with as the user hits the video. To me this is quite high as I have limited calls in a given month. To reduce this can I store the likes, ViewCount and Comments in client side, update the screen with stored data in store and later update the server with one API call after user exits the reel view screen?
I am using React Native, so please guide me if this is do-able. Thank you very much in advance.
I tried calling API as the user hits the like button, I update the like count, then user adds comment I update add/update a comment, if user is engaed for more than 5s I update view count.
But these each updates are increasing my API calls to cloud server. I want to reduce this to as much as I can, and I am expecting someone to help me with this soulution
CodePudding user response:
As you have limited calls, you are heading in the right direction by not updating instantaneously.
Now after taking this decision, you need to store the current count data in a place where it won't be removed after app is closed.
Use a message queue
You can use rabbitmq to queue messages and do updates asynchronously. I believe, this is the most scalable solution. If you expect to have more kinds of these updates, then you should go for this solution.
Use a cache
You can store the counts in local cache in your async storage. Then after exiting reels or a specific period (i.e. send after 1 hour or 30 minutes) you can send updates to your server to sync with the client.
The advantage of such approaches is that even if the user suddenly shut his device down or close his app. The data exists in the message queue or cache. You can easily sync with server after user opens app again.