Remiwi
TTCTheo's Typesafe Cult
•Created by Remiwi on 6/30/2024 in #questions
How to keep a local DB in sync with a DB I don't own?
I'm making a RN/Expo app which is essentially a 3rd party UI for a service. Users add/edit/remove things from this remote database using the App, and the app renders that data in useful ways. At first, I was just requesting/sending data from/to the server as needed, but I would like to support an offline mode. I then made a SQLite database which is meant to stay in sync with the service when online, then when offline it will allow users to see and change data, which sync with the service later.
My current way of managing this has been using React Query, where I'd request data from both the local DB and the service, combining them for display purposes and using mutations to synchronize them. However, every time I try to implement this it becomes really complex, and synchronizing via mutations in react leads to a lot of code dedicated to just making sure syncing from multiple places doesn't cause problems...
I'm considering now only querying the local DB from my react code and performing the syncing behind the scenes. Logically this sounds very simple, since getting and modifying data becomes straightforward with RQ and requires no special cases for working offline. But I thought I'd ask for advice anyways since my last few attempts also seemed do-able but went poorly...
What are some general strategies for keeping a local DB in sync with an online service when both of these can be updated separately? Specifically for the case where I do not have control over the online service, i.e. I'm using someone else's API to access the data.
5 replies