Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CouchDB - Does synchronization copy a database to all users?

I was looking for various information on Pouchdb on the Internet and I liked the idea of synchronizing remote databases with local browser database. The first question that came to my mind is whether it stores a whole database on each device and creates copies on each device? Imagine that I'm creating a chat application and all communications will be stored on all devices using this app. One user can then look into the conversation of others. I looked at the Pouchdb documentation and found filtered replication. Could anybody explain how this synchronization works and whether it is possible to synchronize data only to a particular user?

Example:

Here is a remote database e.g. in cloud, where are saved all informations.

Remote database:

/ user / secret informations /

/ Joe / "secret information" /
/ Dan / "secret info again" /

Here i want to synchronize data only for a particular user. Do not sync whole database but only user specific data.

Joe's device

/ user / secret informations /

/ Joe / "secret information" /

Dan's device

/ user / secret informations /

/ Dan / "secret info again" /

I believe I explained my question. Thanks for the anwers.

like image 864
Raold Avatar asked Mar 07 '23 01:03

Raold


1 Answers

PouchDB can be used in a many different configurations but a common pattern is to have a PouchDB database in a web browser syncing to a remote Apache CouchDB or Cloudant database.

Because the permissions model for Apache CouchDB is "per database" (i.e. you have read/write/admin access on a whole database or not, there is not currently "per document" access control) the mobile PouchDB database synchronises to a cloud "per user" database. That is, if your app has 10,000 users, it would have 10,000 PouchDB databases on each users' individual browsers and 10,000 CouchDB databases on the server side.

This "one database per user" approach is adopted by frameworks such as Hood.ie - it neatly keeps each user's data separate from each others. The drawback is that it is very difficult to query the entire data set as a whole - continuous replication from the "per user" databases to a central database doesn't scale well.

Other solution in this space are

  • Cloudant Envoy which stores all the users' data in a single server-side database, but separates each user by manipulation of the the _id field
  • Spiegel which uses "one database per user" and a replication agent that manages the movement of "per user" data into an additional database, for reporting purposes.
like image 188
Glynn Bird Avatar answered Mar 23 '23 00:03

Glynn Bird