Back

How to implement this offline-first logic in Appwrite?

  • 0
  • General
  • Functions
Márcio Moreira
18 Jan, 2024, 00:53

Hello,

Absolute beginner in Appwrite here, so I would like to know how to implement this using Appwrite, or if it's even possible to use Appwrite in this case.

My project is an app that is offline first and that is multi-user.

The problem situation is the following:

  • User A downloads some documents from the server, then goes offline.
  • User B edits a document and uploads the document to the server.
  • User A, still offline, edits the same document user B had changed.
  • User A goes online and sends the document to the server, overwriting without notice the changes User A had done.

The solution I have in mind is:

  • The server, when receives a document from a client, checks if the updated_at field of the received document is equal to the updated_at field of the document in the server database. Please notice that the client don't change this field. It's the timestamp of the last time the server received this document.
  • If both timestamps are different, it means some other user changed the document while the user submitting the document was offline. The submitting user then receives a warning and may choose between some options what to do.

How can I get this with Appwrite?

TL;DR
Hello fellow developers, I'm new to Appwrite and I need help implementing an offline-first logic in my app. Here's the problem: how do I handle situations where multiple users are editing documents offline and there is a risk of overwriting changes? My proposed solution is to have the server check the updated_at field of the received document against the one in the server database. If the timestamps are different, it means another user made changes while the submitting user was offline. The submitting user would then receive a warning and be given options to handle the situation. If you have any insights or suggestions on how to achieve this with Appwrite, I
ideclon
18 Jan, 2024, 00:59

You’d probably have to implement those checks in a Function, or something - so when uploading, instead of going direct to the Database, you’d pass the data to a Function, which would then either update that in the DB, or respond with an error.

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