Realm trigger - notifications - Is there a way to synchronously or at least first in first out basis when a realm switches from offline to online

We have a React Native app that uses synchronised realm. The realm app in has triggers on insert to a ChangeLog collection. The triggers calls API of a third party solution to send any updates. The ChangeLog collection also serves the purpose of an audit log.

Documents in the ChangeLog collection represent any changes (mainly insert or update) to a set of business collections. These business collections are the main data source of the React Native app. ChangeLog collection is only a mechanism to push all changes to the main set of business collections preserving information for auditing.

As use takes actions in the React Native apps, new records are created or update in business collection and a corresponding change document is created in ChangeLog collection. This change is communicated through trigger → third party API

CHALLENGE: When device is offline, all change documents in ChangeLog collection stay on the device. There may be insert as well as updates on the records inserted. When the device comes back online, ChangeLog is synchronised with Atlas and insert trigger is fired for each document created in ChangeLog while offline. Since the triggers are asynchronous change documents for updates can potentially reach the target third party system before the change document for insert causing failure.

Is there out of the box way in MongoDB Atlas/Realm to send the triggers synchronously or at least send them in the order the records were originally inserted in the ChangeLog collection. It is guaranteed that change document for insert will be added to the collection before the one for update. All we need is to maintain the same order.

1 Like

Hi @Sanjay_Mogarkar ,

As far as I understand, realm changes from client to server sync might get out of order , however this is delt on the server side using a transaction log as listed here:

Now if this mechanism make sure that the writes to the collection explicitly does happen in order and the trigger respect event ordering toggle than events will apply in correct order as they are present in the oplog.

Having said that, I suggest to test your setup under load to verify the actual behaviour.

Hope this clarifies it.