Sync Android Application Database with Remote Database

I am in the planning phase of an Android application that is syncing with a web application. The webpage will be written in Python, possibly with Django or Pyramid, while the Android application will be plain java. My goal is for the Android app to work while there is no data connection, except for the social / web aspects of the app.

This will be a running application, so I want to stick to the fact that it can be easily installed with one click on the market and does not require a separate download, for example CloudDB for Android.

I did not find databases that support this functionality, so I will write it myself. One caveat to writing synchronization logic is some common data between users that multiple users can write to. This is a solo project, so I thought I would do it to see if I'm completely out of base.

  • The application will process local data in the local sqlite database, and then send messages to the service, which will try to synchronize these changes with the remote database.
  • The synchronization service will alternate between checking messages for a local application, that is, changing shared data by other users and recording local changes to a remote server.
  • All data will have a timestamp to track changes.
  • When writing from the application to the server, if the server has newer information, the user will be warned about the conflict and will ask to overwrite what the server is or refuse local changes. If the server has not been updated since the application last read the data, process the update.
  • When data comes from the server to the application, if the server has newer data, overwrite the local data, otherwise discard it, since it will be processed the next time the application is updated.

Here are a few questions:

1) Does this sound like overkill? Is there an easier way to handle this?

2) Where should this treatment take place? On the client or on the server? I think that the advantage of the client is less processing on the server, but if it is on the server, it simplifies the implementation of other clients.

3) How do I handle updates from the server? Incremental poll or comet / websocket? The only thing to keep in mind is that I would prefer to go with a minimal installation in Webfaction to start with, as this is a launch.

Once these issues are resolved, I plan to contribute to the geek community.

+4
source share
1 answer

1) This seems to be a pretty good way to manage local and remote changes + support offline work. I do not think this is too much.

2) I think you should cache user changes locally with a timestamp until synchronization is complete. Then the server should manage all the processing: monitor the current version, make and roll back update attempts. Less customer processing = better for you! (Easier to maintain and implement)

3) I would choose a poll if I want to support offline mode, because in offline mode you cannot open your socket, and you will have to open it again each time you reconnect to the Internet.

PS: Sounds like a VEEERYY OLD question ... LOL

+1
source

Source: https://habr.com/ru/post/1346625/


All Articles