Search code examples
androidrealm

Sharing data among app user using Realm Mobile Platform


I have a question about users accessing data created by another user. I will explain below with a case study.

I am using Realm Mobile Platform. The app uses Realm Auth to allow users to register by email, google and facebook account. At this moment I am using as a REALM_URL: ...":9080/~/name".

I will try to explain what I would like to achieve with the following example. Imaging that I have UserA and UserB. Once the users have registered in the app (using SyncUser), they would be redirected to a project activity. Each user would be able to create their own projects. Before Realm Mobile Platform (Realm Mobile Database), user data was stored in user devices. Now, because I am using "~" in the REALM_URL, when users entered in the project activity, the activity requests and shows all the existing projects for that user.

The app has another activity with a search functionality where users can search for public projects. For example, the UserA makes public Project1. UserB should be able to find Project1 and follow it, or ask the owner to become a contributor. Once the UserB follow or get access as a contributor, Project1 should be shown in the Project activity of UserB.

The question is how to make this possible.

Option A: Use a unique and common Realm for all users. Deleting the "~" from the REALM_URL and adding different fields like "ownerID" to the project RealmObject and a list of subscribed projects to the user RealmObject. This will allow user to query to all the projects (owned and subscribed) in the project activity and search for public projects in the search activity.

Option B: Use two realms, one private for the user data, and one public for projects. The private would have a REALM_URL including the "~" and the public will be absolute. Later, when a new user sign up the app would give privilege (mayRead, mayWrite, mayManage) through the Access Control.

Which one would be a better option? Is there any other better option? Thanks


Solution

  • The answer to your question is, it depends. The Realm Mobile Platform (RMP) will automatically handle all of your data sharing, conflict resolution, and syncing across the users. In this way, RMP acts as a server and single source of truth.

    Both OptionA and OptionB will require this single source of truth and some knowledge of user access control.

    Let's go through the pros and cons of each option.

    OptionA:

    • Pros
      • Only one database, conflict resolution is done by Realm
      • Significantly less work on the mobile side, you just listen to the server
    • Cons
      • Potentially difficult to do user access control

    OptionB:

    • Pros
      • User's private data is completely separate
    • Cons
      • You will be responsible for writing the data conflict resolution between the local database and the server
      • Your app will most likely be larger due to storing multiple databases.

    In my experience, dealing with database conflict-resolution yourself is truly painful. It seems like OptionA is by far your better option.