Back

How to synchronize local and remote database?

  • 0
  • Android
  • Databases
  • Cloud
mayank.12
16 Sep, 2023, 06:08

I have a database on appwrite which is not updated very frequently. Currently to display the data in my app, I have to fetch the documents from appwrite every time the app is launched. To optimize this, I want to create a local database in my app to cache the documents so that it can fetch the data from the local database instead of Appwrite, each time. But I want to know, if I update my database on Appwrite, how do I push the updates to my app's local database. What I want to do is, whenever the Appwrite database is updated, I want to trigger a "push" to the app's local database so that it remains updated. How do i accomplish this?

TL;DR
The user wants to synchronize a local and remote database in their app. They currently fetch data from the remote database every time the app is launched and want to create a local database to store the data instead. However, they need a way to push updates from the remote database to the local one. Two possible solutions are suggested: 1. Use Appwrite's Realtime API to update the local cache whenever there is an update callback. 2. Create a Function that is triggered when there is a change in the remote database. This function can send a silent notification to the app using FCM and update the local database on the received event.
darShan
16 Sep, 2023, 06:15

There are 2 ways to do this -

  1. Use appwrite’s Realtime api & update the local cache on update callback.
  2. Create a Function that is triggered when there is a change in the database, send a sort of FCM silent notification to the app, update local on the received event. This requires dependency on FCM though.
darShan
16 Sep, 2023, 06:37

A problem with FCM here is that it won’t work on devices without Google Play Services. So a realtime connection is recommended.

mayank.12
16 Sep, 2023, 14:18

Can you provide some directions as to how should I create a function for this task?

Drake
16 Sep, 2023, 15:18

How much data do you have?

Drake
16 Sep, 2023, 15:19

Does the data on the device need to be updated while the device is in the background?

mayank.12
16 Sep, 2023, 15:46

currently it's only 10 documents with 5 attributes but it could grow to about 500 documents

mayank.12
16 Sep, 2023, 15:46

no not necesarrily

Drake
16 Sep, 2023, 15:50

That's not too bad. I had 10k documents with a lot of data and the app ended up needing over a gig of space 😆

mayank.12
16 Sep, 2023, 15:55

yeah I am creating an RSS reader app so I just need to store data about some RSS feeds which will not be updated that frequently

Drake
16 Sep, 2023, 15:56

Sooo we're in an awkward place right now because our website has been updated for Appwrite 1.4 but cloud isn't on 1.4 yet...

mayank.12
16 Sep, 2023, 15:59

Any rough estimate for when the cloud will be updated to 1.4 ?

Drake
16 Sep, 2023, 16:01

Maybe next week

Drake
16 Sep, 2023, 16:02

You can start reading the docs: https://appwrite.io/docs/functions

mayank.12
16 Sep, 2023, 16:03

Alright thanks!!

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more