Sync of data between mobile and server - thoughts on architecture?

Hi

I’m new to Couchbase - so I hope I’m not asking a stupid question - and in the wrong category :wink:

I’m already using a NoSQL database but I find the Sync Gateway really interesting. Therefore, I am seriously considering moving to Couchbase as part of a re-write of our app. The re-write will be done in Xamarin that has a plugin for Couchbase Lite.

So that leads me to a couple of questions:

  • Should I create each registered user as a Couchbase user? Or just use a “generic” user for database access? If so, how do I register the user in the first place and authenticate with the server before having registered the user??

  • I don’t want to sync all data between the mobile app and the server. How do I ensure that I only sync data relevant for the particular user? I have general meta data (for all users) and private registrations for each user

  • Do I need a bucket for each user? Or can I “just” (hopefully) have one bucket for all of the different document types and sync against that with some criteria for each user?

Any th0ughts you can share or links to further reading would be much appreciated!

/John

Should I create each registered user as a Couchbase user? Or just use a “generic” user for database access? If so, how do I register the user in the first place and authenticate with the server before having registered the user??

Just another user, not a CB expert, but afaik you need different users for database access. We have a REST API linked to the gateway admin port to manage users and make sure Gateway is in sync with those. If there is a better way I’d like to know.

I don’t want to sync all data between the mobile app and the server. How do I ensure that I only sync data relevant for the particular user? I have general meta data (for all users) and private registrations for each user

You should use channels: Couchbase Capella for Mobile Developers

Do I need a bucket for each user? Or can I “just” (hopefully) have one bucket for all of the different document types and sync against that with some criteria for each user?

You should put all data into one bucket and use channels to split the data.

Thanks Bart!

I’ll read up on Channels - that sound like the way to go!

I’m a little curious as to how you handle the users. My requirement is like this:

  • A new user downloads and opens the mobile app for the first time
  • The meta data is synced to the device (e.g. countries that you need for registration of a new user)
  • The user registers a new profile - and I check that the email address isn’t already registered
  • If Ok, we send the new profile to the server - today via a call to a REST API - but in future I would guess I could do that via sync

Do you have a similar workflow? - if so, how do you do it?

/John

… actually, I guess what I need to understand is, if the Sync Gateway can register a new user as part of a sync? Or if I need individual users as “Couchbase users” (and not just documents of my type “User”) then I’ll have to call my own REST service to create them serverside prior to the first sync?

You need a user account to do the sync with the Gateway, and afaik you can’t create such an account during the sync. You need to either pre-define the users on the Gateway or manage them using the admin REST API. Since the Gateway admin REST API port is not secure you create your own REST API in front of it. It can access user documents in the database through the gateway (or directly on the server). Through your REST API you can manage users, and then have it call the Gateway to update user accounts there as well. You can also add webhook triggers to the sync() function to for example remove a user account if the User document gets updated to enabled: false for example. Our REST API also does the authentication service which provides the token to use with the Gateway for sync.

Ok, thanks!

In the meantime I found this article: Trouble creating a user

It seems that one can create the user via the sync gateway (just using an admin user).

Again thanks for your input!

/John

Server users are not Gateway users. Gateway defines its own users, that are allowed to sync through the Gateway. Gateway then connects to the Server to read/write the data. You don’t connect or authenticate against the Server directly, only through the Gateway, and you don’t use the .NET SDK, but Couchbase Lite for that. Your authentication and user management REST API on the server can talk through the Gateway or directly on the server to query User documents, but it must create the users on the Gateway admin REST API (again, not using the .NET SDK to connect to Server).

Ok, then I think I misunderstood the article I linked to… In that the user was created via the .NET SDK - so I guess that was not a sync. user but then it must have been a database user.

So I’ll need to read up on the sync gateway to see how I register users for synchronisation and use of the database - and use channels to control what data they can access and sync. Thanks for the link :+1:

Thanks for the input :wink:

/John