Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sync PostgreSQL data and ReactNative mobile app data?

I am working on a web application written in Django and using PostgreSQL as the database backend. I'd like to spin up a ReactNative mobile app so that users can operate the app offline. I am concerned about managing database conflicts where a user takes one action offline on the mobile app, takes a conflicting action in the web app, and then the two actions need to be synced, conflicts managed, and merged.

I understand that you don't want ReactNative to connect directly to your PostgreSQL DB from ReactNative as discussed in this question. I also am aware of AsyncStorage in ReactNative. I am unaware of how to best integrate the two. I have seen several questions on syncing web app data with mobile data (e.g., this) but I am looking specifically for a PostgreSQL and ReactNative solution. I see a lot of results for DB solutions in ReactNative, but I am not looking for the new hotness or a pet project that will eventually not be maintained. I've also heard of RealmDB which looks great but does not seem to be free. In short, I am looking for the most reliable, simple, and proven solution for managing data in ReactNative and syncing with PostgreSQL.

I am asking now without any ReactNative code because I want to make sure I set up the ReactNative app correctly from the start, rather than having to go back and rewrite all my data storage code.

To use a very basic example, let's say while on the subway and without WiFi or mobile data, a user changes task_A from incomplete->complete. The user then jumps on his laptop after arriving at work and changes the state of task_A from incomplete->in_progress. When the user gets his mobile device on WiFi and syncs the app data there will be a conflict between the mobile data stored using AsyncStorage and the data living in PostgresDB.

What is the best data storage wrapper for ReactNative given the web application uses Django and PostgreSQL?

I've also asked this on Software Recommendations but it is eerily quiet over there.

like image 698
Scott Skiles Avatar asked Oct 16 '22 11:10

Scott Skiles


1 Answers

You could add pouchDB to your ReactNative app instead of AsyncStorage and connect it to your Postgres DB using pouchDB as mentioned here

UPDATE: It is worth investigating Operational Transformations for future reference:

  • Wikipedia on Operational Transformations
  • github.io on Operational Transformations
like image 157
Naveed Sheriffdeen Avatar answered Oct 23 '22 10:10

Naveed Sheriffdeen