Building offline first app with ability to sync data in 2024


I’m creating my own application and trying to figure out how to properly migrate my application to Realm and Device Sync.

I was faced with a difficult question for myself and did not find a clear answer in the documentation that would suit my needs.

My question: how to stop synchronizing user data with Atlas for an indefinite period of time? For example, the user may log out or his paid period may expire. Or it may not start yet, but user will start working with the application locally to begin with.

The documentation says that manually stopping synchronization for a long time is not worth it. How can I then solve this whole matter? Every time a user logs in and logs out, should I copy his data from one database to another? This seems like a bad idea. It could be GBs of data!

An application about notes. Notes can be recorded locally as much as the user wants without the Internet or payment. Then, when the user enables synchronization, the data should be synchronized with the second device.

Moreover, for flexible synchronization, the documentation says the following: if you did not synchronize this model, but recorded it, the server will cancel this recording on your device. How to deal with this? Losing user data is unacceptable.

I am using Realm. Kotlin. Android. And I plan to move to KMP.

I would recommend keeping two separate realms, one for synced data and one for unsynced data. I’d imagine that if a user logs out, they can’t interact with their data at all.

Our users who implement a “free locally, paid sync” model do roughly what you’re describing - write the data to an unsynced realm to begin with, and then copy it over to a synced realm when the user upgrades

You are partially right. Indeed, it would be good to copy the data to a new database, but there are, in my opinion, very serious “but”:

  1. The user logs into the application and logs out just to have fun. How will the application behave?
  2. The user no longer wants to synchronize data, but is still a paid user. Will we transfer the data back?
  3. The user’s premium subscription has expired. Are we transferring the data back again?
  4. The user has not been online for a long time because he expects the application to be offline first and after a month only turns on the Internet. What will happen to his data? Do we just delete them? This is an unacceptable situation.

From all this synchronization, I get the feeling that the database was made for websites because only on them can users be online quite often.