Search code examples
javascriptdatabasecouchdbcouchdb-futon

Is it good practice to give each CouchDB user a separate database?


I have a bit of conceptual question regarding the structure of users and their documents.

Is it a good practice to give each user within CouchDB their own database which hold their document?

I have read that couchDB can handle thousands of Databases and that It is not that uncommon for each user to have their database.

Reason:

The reason for asking this question is that I am trying to create a system where a logged in user can only view their own document and can't view any other users document.

Any suggestions.

Thank you in advance.


Solution

  • It’s rather common scenario to create CouchDB bucket (DB) for each user. Although there are some drawbacks:

    • You must keep ddocs in sync in each user bucket, so deployment of ddoc changes across multiple buckets may become a real adventure.
    • If docs are shared between users in some way, you get doc and viewindex dupes in each bucket.
    • You must block _info requests to avoid user list leak (or you must name buckets using hashes).
    • In any case, you need some proxy in front of Couch to create and prepare a new bucket on user registration.
    • You better protect Couch from running out of capacity when it receives to many requests – it also requires proxy.

    Per-doc read ACL can be implemented using _list functions, but this approach has some drawbacks and it also requires a proxy, at least a web-server, in front of CouchDB. See CouchDb read authentication using lists for more details.

    Also you can try to play with CoverCouch which implements a full per-doc read ACL, keeping original CouchDB API untouched, but it’s in very early beta.