What is the best architecture for synchronizing user data across devices where user data is unique to them using couchbase server and sync gateway?

78 views
Skip to first unread message

Akeem P

unread,
Jan 20, 2014, 1:25:43 PM1/20/14
to mobile-c...@googlegroups.com
I have an app I'm developing where I'd like each user to sync their data across devices as well as on the web. The data is unique to them and I'd prefer to not necessarily mix different users' data in one database. My initial thought was each user get's their own database and use sync gateway to sync them (that seems to have been the prescribed couchdb way though this isn't necessarily couchdb) but I'm wondering if this is the best architectural way to do it. On another forum someone mentioned using channels but that seems to come with it's own limitations (e.g. I'd have to figure out how to make the ids unique to a user so that they can co-exist in one bucket).

Jens Alfke

unread,
Jan 20, 2014, 3:04:25 PM1/20/14
to mobile-c...@googlegroups.com

On Jan 20, 2014, at 10:25 AM, Akeem P <akeem.p...@wepala.com> wrote:

My initial thought was each user get's their own database and use sync gateway to sync them (that seems to have been the prescribed couchdb way though this isn't necessarily couchdb) but I'm wondering if this is the best architectural way to do it.

With CouchDB it's the only way to do it. It's a reasonable approach as long as there is no shared data between users (otherwise you have to set up a large number of server-to-server replications to keep everyone's shared data in sync.) It does require that you create some server-side infrastructure to create and provision new databases as new user accounts are created.

This approach will not work with Couchbase Server because buckets are quite heavyweight. Each bucket reserves RAM and is kept 'hot' by the server for maximum performance, but that means that you can't realistically have more than a dozen or so on a server.

The Sync Gateway is based around the design of putting all the data into a single database and using channels and access controls to keep private data private.

On another forum someone mentioned using channels but that seems to come with it's own limitations (e.g. I'd have to figure out how to make the ids unique to a user so that they can co-exist in one bucket).

If the doc IDs are significant to the app, then use the user ID as a prefix (e.g. "jens:highscorelist").
If they aren't significant, you can just use UUIDs by letting Couchbase Lite make up the doc ID for you.

—Jens

Akeem P

unread,
Jan 20, 2014, 3:42:34 PM1/20/14
to mobile-c...@googlegroups.com
Thanks so much for the explanation. 

WIth respect to the doc ids I shouldn't be worried about a generated id on one person's phone conflicting with the id that someone else's phone generated?

Jens Alfke

unread,
Jan 20, 2014, 4:21:44 PM1/20/14
to mobile-c...@googlegroups.com

On Jan 20, 2014, at 12:42 PM, Akeem P <akeem.p...@wepala.com> wrote:

WIth respect to the doc ids I shouldn't be worried about a generated id on one person's phone conflicting with the id that someone else's phone generated?

Well, UUID stands for "Universally Unique Identifier" — the chance of two independently generated UUIDs being the same is effectively zero.

You do have to worry about malicious collisions, where someone intentionally tries to push a conflicting doc ID.  (But this is true however you generate the ID; UUIDs actually help here because they make the doc IDs unguessable.) Those should be caught during document validation on the server.

—Jens
Reply all
Reply to author
Forward
0 new messages