Watch keynotes and sessions from MongoDB.live, our virtual developer conference.

Best practice for stop sync

Hi everybody,

In my app, I want to implement sync as Premium feature.

  1. When user is not paid, I’m using a local DB
  2. When an user paid, they can use a sync Realm Cloud DB

My question is, if a user stop paid, I don’t want to allow them use the sync feature, what should I do? Manual sync from Realm Cloud DB to local DB or there’s a better solution?

Tks in advance

From what I have understood there is no way to pause the syncing, so my understanding is that you would have to use a different realm file and then copy the data over.

With MongoDb Realm it seems like it is a lot easier to keep the data models the same in the local realm and a synced realm, but I don’t think this is an easy use case.

I plan to do something similiar though. In my app, each user can do well over 1000 edits during a session. If I would commit each of those write transactions to a synced realm it would be expensive. What I was recommended to do in this case was to do my edits locally (on a local realm) and then copy them over to the synced realm when done, which would drastically reduce the sync operations used.

Not sure if this helps, but I’d also think thought the database structure from the start to make it easy to move between realms. In my case, it means avoiding relations and top level objects when necessary and favor embedding documents. If one document is a separate unit with few dependencies it would be easier to move the data from local to synced and back.

Not sure if this helps, but this is my 2 cents.

Which SDK are you using? Most have an API to pause/resume sync exposed on the Session object. For example, in JavaScript it looks like realm.syncSession.pause().

When you pause sync and then resumes. If you make multiple commits to the local database while paused and then resumes. Does that count as one realm sync operation or do you still count every commit?

I’m thinking about the same, but there’s a problem :
An user uses 2 devices : A and B. When he make changes on device A, the local DB on device B is not updated, then when he stop using “premium”, the local DB on device B is not the newest one, he lost data.

@Simon_Persson We still count every commit.

@Nguyen_Dinh_Tam A user would presumably login with the same account and therefore have the same data on device A and B. If he chose to stop paying for premium service then you could make sure that all changes were uploaded before stopping sync.

1 Like