Search code examples
iossynchronizationrealmrealm-mobile-platformrealm-object-server

Realm Object Server - When does syncing occur?


I have an iOS app powered by a Realm Object Server hosted on Amazon and I am curious as to when syncing actually occurs. Is syncing lazy on queries, real-time for all open realms, or something else?

For example, let's say I have a realm called /common and all SyncUsers have read/write permissions to this realm. Each active SyncUser also has a notification block listening to a GlobalProfile object in the /common realm corresponding to their SyncUser identity. If one user makes changes to another user's GlobalProfile object, will all users download this change immediately, or will only the user with the notification block on this object immediately download the change?

Specifically, I want to create a way for a user (let's name it Tom) to search for other users and send them read/write permissions to Tom's realm. My current solution is a public realm in which each user adds a GlobalProfile object. To search for a user named Jerry, Tom can simply query the public realm. To grant Jerry read/write permissions to Tom's realm, Tom can write a SyncPermissionOffer.token into Jerry's GlobalProfile. Because Jerry has a notification block listening to his GlobalProfile, he will be immediately notified of this token and can accept the SyncPermissionOffer to Tom's realm. My worry, however, is that all users, not just Jerry, will sync this change in the /common realm, which is unnecessary. If the app has 100,000 users, I don't want each user to constantly sync all SyncPermissionOffer tokens being sent between other users.

Please let me know if this question is not clear. Thank you so much for the help!


Solution

  • Sync is real-time on all changes. Sync is not waiting for, or contingent on, a notification block. The notification block is executed locally and is not used to alter the client-server communication in any way.

    If you have a /common Realm, it will contain all your permission offers and all users will download all other users permission offers. It will grow large over time.

    What you could do is to have a /common Realm that only contains the user ids, their "names", and a path to their "inbox" Realm. When user A wants to invite user B, A looks up B in /common, obtains the Realm path for B's inbox, and sends a permission offer to that.

    With this approach, the common Realm would not grow that big, because the data par user could be kept below 100 bytes, say.