Flexible sync, right choice?

Good morning,
we’re developing a new application and we are figuring out what would be a good architecture to choice.
In the past we used realm as embedded db for some mobile applications.
the idea of realm sync and the concept of a mobile serverless application is very fascinating.
We have some
questions in order to understand if flexible sync technology can do for us.
The context is:
A new mobile application (android and ios) that shows to users a set of plant cards that can be viewed in read-only mode and used in offline mode too (if no connections are available)
Every card has one main section with general informations and differents linked subsections.
Every user can search a plant with a dedicated functionality based on n-criteria. The starting set is around a thousand of cards, but the aim is to reach the order of one million (Would be possible?). Each card would be implemented by a main realm object that has embedded objects inside it that represent the various sections. Could Flexible Sync be the right solution? is there a way to limit the size of the database locally? Is it possible to search for a card starting from an attribute of a subsection?
The initial subscription has to contemplate the entire set of cards?
Thanks in advance.

Hi, Im glad you are contemplating using flexible sync. My initial reaction is “yes” it can definitely help you. You can use permissions to enforce it is read-only, and the system is capable of sending millions of objects (obviously performance will be impacted by a combination of (a) the size of the data set (b) the size of the result set for a particular client and (c) the average size of the objects in the result set, but I would recommend getting started and it should be pretty easy to test. I would just caution you that if you plan on doing any load/performance testing you should use an M10 or above since M0’s and M5’s do rate limiting and the performance will likely bottleneck there.

As for your second question, it is hard to answer without too many specifics but if you have a sample data model / schema and some notion of how you want to query them I would be happy to look at it.


1 Like

ok, thank you, tomorrow i’ll send you a sample model so you can better understand what i’m talking about.

Hi again, i uploaded some models (Kotlin language) that describe the plant card (PlantCardRealm), an example of related section (SectionPlantingConditionsRealm) and, at last, a sort of bean class(SectionPreviewDescriptionItemRealm) that allow us to put inside any field a initial description and a more discorsive detail. The number of related sections is 10, with about 5-10 fields per section. have the cardinality of the initial description some impact on the space of the embedded realm in app? Is it possible to define a subscription with a query on a field that belongs to embedded object? I’m thinking about a million of cards and the impact on local db. thanks.

PlantCardRealm.txt (1.0 KB)
SectionPlantingConditionsRealm.txt (959 Bytes)
SectionPreviewDescriptionItemRealm.txt (1.4 KB)

Hi, Ill try to answer some of the questions in order:

Have the cardinality of the initial description some impact on the space of the embedded realm in app?

I am not entirely sure what you mean by the above. I do think in general that space is pretty well optimized and this is probably something that you shouldn’t worry about too much right now unless you are very space constrained on your device which is normally not the case.

Is it possible to define a subscription with a query on a field that belongs to embedded object?

Unfortunately it is not. See here: https://www.mongodb.com/docs/atlas/app-services/sync/data-access-patterns/flexible-sync/#eligible-field-types

Note that once the data is on your device you can use the entire realm query language to have your app’s logic utilize the data (and here you can query on embedded objects), but you cannot only sync down a subscription of data that is of the form "lightRequirements.previewInfo =="more information". What are you trying to subscribe to ideally?

I try to explain my worries:
In a couple of years we would like to enrich our database with many plant’s card, the goal is to add more than 1 milion of cards.
We did an initial test in which we duplicate 1,5 milion of times an example card. The local Realm db exceeded 1 giga of bytes, that for some users could be,
potentially, annoying.
I was thinking that using subscriptions would allow us to maintain a lighter version of the local database, because every subscription brings to local
a subset of the original database. Isn’t correct?
In this way we could define a set of subscriptions, and after choose the right one for the current purpose.
This was the initial idea, i don’t know if it’s correct or if there’s another way to reach the goal.

Hi, the size of the database is a function of (a) the number of objects (b) the average size of those objects and (c) the rate of changes to those objects since history is stored and compacted. So I am not sure how much you expect that data to be on your local DB but that seems resonable for a million objects that are each 1KB in size

Yes, that is how subscriptions should work. You define the subset of the data that you would like to sync down:

Ok, the subscription idea is very “powerfull” but it’s a big limitation that you cannot create a subscription using embedded fields inside the query definition of it
In our case the final size of database is too big to replicate and store in a smarthphone. Without the possibility of creating dynamic partition of it (using subscription) we have to change solution, using standard api rest to retrieve only the subset useful in a determined context. I’ll check if flexible sync will be updated with this implementation in the future. Thanks so much.


Hi. I am still a little confused what query you are trying to make? We will certainly continue to make the product better and including embedded fields as “queryable” is on the horizon, but in the meantime you can change your data model ever so slightly in order to avoid this limitation.

I see you posted your schemas above, but I am not quite sure what the query you are trying to make is?

hi,Tyler, what do you mean with “change your data model ever so slightly”? The problem is that i can’t do a subscription based on embedded fields logic, and so … how can i bring into the local realm only a subset of the entire initial Mongodb’s set? I try to explain with an example: suppose having 1 milion of plants cards into Remote Backend. The client (android) needs to retrieve only some cards based on different search criterias, for example the “difficultyLevel” inside embedded object “SectionPlantingConditionsRealm”. How would you handle a situation like that? (And many others dealing with different search criterias in differents embedded objects?) How can i do this without having an exact replica of the Mongo db in the local Realm db? Am I missing some concept?