How can data synchronization be performed between devices?
Context: In my app, I have collections that have decks that have cards.
I wanted to add the auto-sync feature (a toggle) in settings.
So that if information is created/modified/deleted on one device, when I access the app on another device, the changes will be visible (if the auto-sync toggle is enabled).
I know I can simply retrieve the collections from the database, and if I click on a collection, it will retrieve the decks in that collection from the database, and the same for cards when I click on a deck.
But I'd like to take advantage of using a local database to avoid repeated queries, like a cache, but I'm not sure how to implement it.
For example, if the user creates multiple collections, decks, and cards and then enables auto-sync, a lot of write operations will be performed, and it could be abused.
Another problem would be how to know if it should load data from the database. For example, if a new collection is created on one device, when it's accessed on another device, how does it know which collections to read to update its local database? I don't know if I'm making myself clear; it's a bit confusing.
Another option would be to not have an auto-sync toggle, and instead have the collection, deck, or card options be able to click on "Cloud Backup", that way you could avoid the massive writing I mentioned before, although there would still be the problem of how to tell other devices to only read that new collection/deck/card that was added to the database so that it adds it to its local database (and avoid calls to the database, which would be fast)
It's a somewhat complicated topic. I welcome any recommendations or ideas (even if it's a different way of doing it).
1 Reply
Another option I just thought of would be to have a section with all the collections that have been clicked on "Cloud Backup" (these are loaded from the supabase database). If you want to save it to your local database (i.e., in your app), simply click the download button. While it won't download to all devices when you click "Download," it will be available on all when you access the "Cloud Backups" section (let's assume it's called that). And all devices will be able to download it if they want. (That's what I'm most interested in right now.) I'm open to ideas.