S
S
Sergey Karbivnichy2021-12-28 17:39:31
Database
Sergey Karbivnichy, 2021-12-28 17:39:31

How to synchronize the database between devices?

I write note-taking apps. If I have no problems with the technical implementation of applications, then it is very difficult with "algorithms".
Given:
1) Application for Android (on basic4android)
2) Application for PC (Windows, Linux) on PyQt5

I chose these technologies, as they are the simplest and I understand them.

This is how remotely I imagine the work of applications:
On my phone, I create brief notes (visit a website, watch a certain movie, download a song, make an app for something, etc.). Next, I come home, run the application on the PC, and press the sync button (the phone and the PC are on the same network). (I have not yet decided where the server will run - in the application on the PC, or on the phone, or both - but this is not important yet). Next, a window appears asking you to specify the ip-address of the "server", or a search is made on the local network for working hosts, then requests are sent to addresses with the desired port and in the request, for example, hello, and if the desired response is received, then the server. Then the most interesting - synchronization begins. This is where my problems start.

Possible situations:
1) There are 2 notes on the phone that are not on the PC. There is one note on the PC that is not on the phone.
2) A note has been deleted on one device that is on other devices, and I need to delete this note during synchronization.
3) And many more situations that I don't know about yet.

It is clear that for each application you need to create a unique identifier. This is where my thoughts ended. In general, as I understand it, I need to do approximately the same thing as in Chrome for bookmarks.

Ideally, it would be nice to hear specific synchronization algorithms (possibly with some kind of pseudo-code), or links to articles. In Google, 99% of the results for housewives are on how to sync Android contacts.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2021-12-28
@hottabxp

I did the same for a database with heterogeneous data, when we have some rather large database on the client that needs to be synchronized with the server in conditions where each transmitted byte of data counts.
The algorithm is approximately the following:
We keep a separate log table - which entries were added, which ones were deleted, which ones were changed. Each log entry is tied to some id - version number.
A certain client, upon request, sends its version number first. In response, you issue records - all changes from the client version to the current one. After that, the client synchronizes its data - deletes deleted records, requests new and changed ones.
After synchronization is completed, the current version is incremented on the server, and all changes in the database will be with the new version.

N
Nikolay Savelyev, 2021-12-28
@AgentSmith

Mdaaaa ... Well, you and the gesture you wrote here. I don't want to use this crap.
Synchronize by timestamp and status and you will be happy

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question