Back

Syncing two collections, on different installations of Appwrite

  • 0
  • Self Hosted
  • Functions
Rushour0
6 Apr, 2023, 16:53

Hey do you have any code sample for this?

TL;DR
The user wants to sync two collections on different installations of Appwrite. They are experiencing a delay of 6.5-7.5 seconds between making a request and the execution of a function. They are looking for a faster solution. One suggestion is to scale out horizontally with more workers. The user is advised to store something on the document to know if it needs to be updated or not. They also discuss the need to avoid infinite syncing loops and provide a possible solution using a flag. The user provides more details about their specific setup and the problem they are facing. The support team asks for a code sample to better understand the issue
Drake
6 Apr, 2023, 17:14

Is the problem that server A has data and it gets synced to B, but then B tries to sync that back to A creating a loop?

Ponguta_
6 Apr, 2023, 17:26

Huge code right now, because I'm testing lot of things.

Rushour0
6 Apr, 2023, 17:27

Fair enough

Ponguta_
6 Apr, 2023, 17:32

Think like, server B (remote) gets new data, a function catch that data with an event, and put it on a collection called SYNCS, that collection is a queue to sync to server A (local).

On server A there is a function that set flag ON in server B (remote), so server B will ignore new events (during the execution of this function).

Then, the same function starts syncing data on queue (SYNCS collection) the problem, and finish the process setting the flag OFF.

Problem: The Function A (the one that is triggered by an event) is executed after Function B finishes, so FLAG is OFF by that time, so it will generate new SYNCS documents, that is not the intended.

Ponguta_
6 Apr, 2023, 17:32

I could try to make a diagram if you guys need to understand better

Drake
6 Apr, 2023, 17:45

let's take a step back and don't think about your implementation...what are you trying to do?

Ponguta_
6 Apr, 2023, 18:57

That's a good Idea.

I have two appwrite instances, one running locally, and another on internet (call it remote).

In both, there is a collection, and I want to sync bidirectionally this collections. Like, if I add something to the collection on the remote server, it will replicate the same on local. The same happens in local, if I add something on its collection, it will replicate that on remote.

This have to work for CREATE, UPDATE, DELETE

Drake
6 Apr, 2023, 18:59

And so if a document is synced from remote to local, you don't want that change to get synced again from local back to server in an infinite loop, right?

Ponguta_
6 Apr, 2023, 19:07

Yes sir!

Drake
6 Apr, 2023, 19:18

Right so you need a way to know there's no need to update...

I think you're going to have to store something on the document to know. Maybe you can store who updated the document: sensor or sync. If it was updated by sync, don't sync

Ponguta_
6 Apr, 2023, 21:19

I though on the same, so I will implement that, to check how it works with that

Ponguta_
6 Apr, 2023, 21:20

but actually, reading from you that work around points me in the right direction

Ponguta_
6 Apr, 2023, 21:20

thank you so much Steven

Ponguta_
6 Apr, 2023, 21:20

And sorry for my late reply, working a lot today!

Drake
6 Apr, 2023, 21:20

no worries!

Tessa
7 Apr, 2023, 21:05

@Ponguta_ everything good? Checking to see if it makes sense to close this and mark as solved 🙂

Ponguta_
7 Apr, 2023, 23:28

It's needed to mark it as solved?

Tessa
8 Apr, 2023, 00:30

Checking if everything is good and if you still needed any assistance

Ponguta_
14 Apr, 2023, 17:14

Just as a little update on this.

IDK why this happens, if is just me, or what. buuut.

Seems like the time passed from the request made with databases.update_document('[DATABASE_ID]', '[COLLECTION_ID]', '[DOCUMENT_ID]') and the execution of a function that catch that event is around 6.5 - 7.5 seconds.

What I mean with this.

If I set the a flag ON, to stop catching events, this flag should be ON for at least that amount of time, before going OFF, otherwise, it will be useless.

Drake
14 Apr, 2023, 18:10

events get queued and, on self hosted, they're executed serially. So, if you have other events going on, they may be processed first before this update document one is processed

Ponguta_
14 Apr, 2023, 18:33

any way to do it faster? or thats just how it works

Drake
14 Apr, 2023, 18:47

You would have to scale out horizontally with more workers that can handle the events

Ponguta_
14 Apr, 2023, 19:09

Any guide on how can I do that?

I really want to try that out Steven

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