How many realms per cloud instance?


#1

I am designing an application that will need to store secure information for each user. Based on the following excerpt from the documentation I am considering isolating each user into their own realm:

For example, suppose you have an application where users have to log in to your web backend, and you want to support quickly switching between accounts. You could give each account its own Realm file that will be used as the default Realm by doing the following:

func setDefaultRealmForUser(username: String) {
var config = Realm.Configuration()

// Use the default directory, but replace the filename with the username
config.fileURL = config.fileURL!.deletingLastPathComponent().appendingPathComponent("\(username).realm")

// Set this as the configuration used for the default Realm
Realm.Configuration.defaultConfiguration = config

}

My question is that the pricing for the Standard cloud package states that it supports up to 3 instances. Using the example above, would each user’s realm count as one of those instances, or can one server instance support many individual, isolated, synchronized realms? If the latter, is there an upper limit on the number of realms that an instance can support?


#2

You can have 3 server instances with a basically unlimited amount of realms.


#3

Awesome, thanks for the quick reply!


#4

Please, let me join the thread.
Excuse me if I ask a ridiculous question - I am completely layman in REALM.

As part of the standard cloud account fee.

If I understand correctly, in one instance, I can register (email / password authentication) very large number of users.
Any of the registered users can have their own private database?
Each database will consist of the same model (e.g. 2-3 “tables”) and many “records”?

Comparing this to traditional SQL. it works as if we had separate “private” tables (or database) for each user (in which he can add / modify records)?

We do not need to create a field (“column”) named user_id in each table - as it would be in traditional databases.
And when specify user_id in queries to retrieve only the records assign to current user.
Because every user has their own tables / database? And choosing the right private database (and separation users data: “records”) is automatic after authorization by email / password?

Thanks for your time.


#5

If you want to think realm as a traditional SQL, then you can think of the realms as individual databases. You can add to users read/write permission to that database but generally, only the creator user will have access to it.

When you use realm, you need to give a unique realm name per user (most of the time is an userid) and you will use that id to open the actual realm.

In the older realm versions, we used to have a global realm (storing all the users login data) with access to everyone, and a single realm per user to store the private data. This logic still works, but right now the realm guys try to go on other ways.

We do not need to create a field (“column”) named user_id in each table - as it would be in traditional databases.

I don’t think, that this statement is correct. Its correct in the way that each user has their own realm, so they can access only their data [this means that we don’t need to store userId] -> but if you plan to share these realms between users (like a note sharing app) then it’s better to have the userId.


#6

Thank you very much for your answer. It explained a lot to me.

If I do not plan to share data between users. I can choose one of two options:

  1. A single private realm for each user.
  2. Using one global database with the column / field, userId in each model (table) to distinguish the records of a particular user.

Is any of these options more preferred / recommended?

One more question:
Can the user simultaneously log on to several devices (phone, tablet etc.) to the application (using a single private Realm per user)? As I understand, on each device made changes (adding record / editing) should be synchronized correctly?

Thanks for your time.
Bestr Regards


#7

In your case i would go with the first option.
There isn’t any limitation about device count per user in realm. The syncing is made instantly.

In a real app situation its much more hard to build correctly - specially the migration code and handling the offline/online devices. Just prepare yourself for that :slight_smile:


#8

Thank you very much for the detailed answers.