I have a project consisting of both a local and a remote system.
The database between the local and remote system needs to perform 2 way syncing. I know this can be achieved by using a 2-way syncing pattern.
However, my client will update their version at different timing, which leads to different versions of client sync to 1 remote server.
What is the best practice to handle these situations, especially when the schema changes?
Update 1: Sorry for the poor question being asked, here are the details of my study.
For 2 way syncing, the solution I found over here matches my requirement. Basically, the client will have to resolve a conflict if there are any conflicting changes.
However, the hardest part is how to remote server handle multiple local clients with different versions of the data.
My current 2 approaches are:
add metadata, a.k.a version for every record of data.
- The data is handled in a single large database.
- There's a column to store the local client id and data version.
- When the server adds new data, it needs to determine the current version of the client, then transforms the data to that version.
- When the local client adds new data, it'll attach its id and current version before syncing to the server.
- The server-side needs to add another layer to handle multiple versions of data when needed for computation.
- When the local client schema is updated, I will run a schema migration on both local and remote (specific to that client data), so that my local schema has no need to maintain backward compatibility of its own data.
The problem with this approach is I can't (maybe I'm wrong?) use a Relational Database. I must use the document-based database because there are multiple schemas in a single big database.
Then I went for the second approach.
create a database for each client.
- My local client grows 20 ~ 30 each month, with maximum 60k, still possible to maintain each database for every one of them.
- Each local client will sync to their own database in the remote server which has the exact same schema as local.
- The server-side needs to add another layer to handle multiple version of the database when needed for computation.
- The syncing can potentially be done on the database level (eg: master-master).
This is my current choice of approach, but I still have not much confidence in it, especially when the local client performs the update. I am still figuring out the way to make sure both remote server and local clients are updated correctly.
I hope this explains my question better.