lundi 28 mars 2016

Caching a post system with users

Background

Imagine a post system like Twitter. You have posts and each post has a user which posted it. I am trying to do something very simillar to this, but I can't find a correct way to do.

The main problem is cache everything, because I don't want download all the posts every 30 seconds, for example. To solve this, I simple get the date from the last post from the server and the last post from the local db, if it's different, update it. The problem is: if someone change the text from some post that is already on the local database of the user, it will not be updated. Let's call this Issue #1.

The next problem (and most problematic) are the users. Each post shows the avatar of the user that posted it, so I can't simply cache the posts, because if the user changes his avatar, the cached version will stay with the last avatar (due to Issue #1 too). To solve this I use a common avatar URL, but what if the posts has the name of the user? It's the Issue #2.

My solutions so far

To solve the Issue #1, I thought on adding versions numbers to every post, and when someone edits it, the version number is increased. If the version number of the post is different from the database, the post content is downloaded again and update. But if I have so much posts, the requests will become expansive and overload the server if multiple users are using the service.

To solve the Issue #2, I thought a similar thing as Issue #1. I add a version number on each user profile. If the user updates it, then the version number is increased. When the posts are loaded, I send a request to the local database to retrieve the user profile, then it checks the version number and if it matches with the server, return it, otherwhise, update and return. This would be expensive too, especialy if the user just update his name and I redownload the avatar, but for this I can have two separated version numbers.

The question

What is the best way to deal with this kind of problem, the most scalable solution that don't overload the server with requests and don't download a lot of unnecessary things on user's smarthphone?

What I'm using

I'm first doing it on Android using SQLite to store the data. I use Socket.IO to fast communicate with the server and to receive the requests.

Aucun commentaire:

Enregistrer un commentaire