Home > OS >  How to achieve synchronization and backup using Realm Sync?
How to achieve synchronization and backup using Realm Sync?

Time:05-23

I am planning to develop a cross-platform app for iOS and Android and would like to sync the data via Realm Sync. Realm Sync is serverless. Let's assume the following case: A user only has one device, uses the app, saves data and the device breaks down. Then there would be no way for that user to recover their data, since Realm Sync is just a sync and not a backup, right? But how can you implement synchronization and backup within the framework of Realm? What role does MongoDB Atlas play?

Many thanks in advance!

Note: I am an undergraduate student.

CodePudding user response:

Realm Sync is cloud based - meaning there's a cloud based server that stores the app data remotely

The data is stored locally first and then automatically sync'd to the cloud at a later time (usually within seconds or faster). That's why Realm is considered an "offline first" database; data is stored locally (offline) and then copied/stored online.

Realm can either be a purely local only database with no cloud sync or can be a synchronized online as a "real-time" cloud database. (or both!)

When sync is used, the database that backs Realm is called MongoDB, and is a NoSQL database.

Generally speaking, when a Realm client app is developed, the SDK you choose is the layer between your code and objects and the MongoDB back-end database.

The SDK allows you to code in an object-oriented way without the need to directly work with the low level NoSQL objects.

You create models, relationships and the UI and the SDK takes the app data, massages it, and stores it in MongoDB as NoSQL.

As a followup so future readers don't have to read through all the comments:

Q) what does the term "serverless" mean?

A) I like this definition

Serverless offloads all management responsibility for backend cloud infrastructure and operations tasks - provisioning, scheduling, scaling, patching and more - to the cloud provider

and the more straight and too the point:

Serverless is a cloud development model that allows developers to build and run applications without having to manage servers.

Q) Doesn't that mean that the data is then only temporarily stored in the cloud

A) Not at all. As mentioned above, Realm data is always written locally first and then the SDK sync's it to the cloud. If you totally erase your device, once you reinstall and run the app, Realm will pull down the data from the server (sync)

Q) Because the prices for Realm Sync also do not include storage space costs: Pricing

A) That link includes storage per plan and costs: In summary

Shared plan is up to 5GB, the serverless is up to 1TB and the dedicated is 4TB per shard. Then, Shared is $0/Month, Serverless is .30/million reads and dedicated is a flat $57/month.

Q) Is it then possible to save the user data on this (an Atlas cluster)?

A) YES! That's the whole idea! BUT. If you're developing in Realm, it's you job to craft a great app using the SDK, and let the SDK interface with Atlas (MongoDB) on the backend. Depending on your use case you may rarely need to do anything with Atlas directly.

The big picture is that when coding with Realm, you work with objects, structures and relationships in a more much natural object-oriented way - the SDK does the heavy lifting of taking that data and 'converting' it for storage on the Realm Sync server (MongoDB Atlas) - as it ends up being NoSQL.

  • Related