CouchDB and PouchDB with database per user

If we have a SaaS app with multiple clients/accounts, is there a way to limit what is synced to only data related to the client(s)? Hopefully there is, or could be, a connection to Security Providers to limit what is synced.

I wouldn’t want someone to access the database outside of the application interface and see every other client’s data.

1 Like

Or could the local copy of the database be encrypted so it’s only accessible through the app?

I’m just imagining a SaaS that has large amounts of data, I wouldn’t want all of that being synced to all clients.

Examples: gmail or salesforce

Maybe these types of apps are not ideal for couch/pouch, but any app with a large amount of data would probably want some way to limit what is synced.

You could have multiple CouchDB databases with different sets of data to be synced.

You can even have a primary relational database that copies a subset of data to the CouchDB to be synced with the clients.

Separate database per client is not supported as you can’t sync it with one central database.

Which security provider you will only be able to secure and restrict the database access but not the data, so it is all or nothing.

So indeed as the full database is replicated to all clients ( also with uploaded files in it which we will support shortly) it will have specific use cases when you need your full database available offline.

This is from 2015, but looks like there is “filtered replication” as on option.

https://pouchdb.com/2015/04/05/filtered-replication.html

Official docs discuss it as well and that there are two potential ways ( Selector Objects and Filter Functions)

https://docs.couchdb.org/en/stable/replication/intro.html#controlling-which-documents-to-replicate

It would be great if we could hook that up to some db table/value (currentUser.account = record.account) so only records the client should get are sent from couch to pouch.

This article talks about SyncGateway as an option for multitenancy and using userid.
https://medium.com/@asi_73084/pouchdb-syncgateway-for-saas-web-apps-the-missing-guide-22e33e148277

1 Like

Where was Couchbase Mobile/Lite when we pushed for this? :slight_smile: Seems like it recently introduced scopes and collections that would help with multi-tenant data seperation.

I have also been wondering how to integrate / use CouchDB/PouchDB in a SaaS project where each clients’ data is stored with a clientID that is used to filter from the pool of data.

2 Likes

With CouchDB there is a possibility to have a database per user. Actually working with CouchDB is different as databases are very lightweight and you can have a lot of them on a single server.

So you can be working with multiple databases, some shared for all users - others specific user dedicated.

On the clinet side you connect only with the databases you want to sync, like the common ones and the user specific ones.

We will investigate if you can add also an option for per user databases. But we will have to also adapt the security provider to this model as well.

See also for more info:

Could the per user model work for an app that has tenants/accounts with multiple users that will need to access the same data?

2 Likes

The client separation by unique user id regarding data synching is, surely, by far, the most necessary commercial business expectation.

It seems, at least conceptually, that couchDB will function in a multi-tenant SaaS app. However, if there were some examples of this kind of scenario in Wappler, it would be easier to comprehend the integration and encourage user adoption of the technology.

1 Like

I echo @guptast’s perspective!

I’m wondering about the details of how we sync our existing multi-tenant database to the Couch/Pouch world…

Is this product something to consider?

https://www.cdata.com/kb/tech/couchdb-sync-mysql.rst

One challenge I may have with doing everything in Wappler is that my database is created and managed outside of Database Manager and is highly dependent on things that Database Manager doesn’t support like MySQL views…

Perhaps we should actually wait until the feature is finished and documented before going down this route. If this is a full implementation there is so much more to come!

CouchDB is highly flexible and should easily be capable of multi-tenanted database structures but no doubt it requires a completely new approach and a new way of thinking as it can be much more granular in approach, for example each tenant feeding it’s own couchDB via pouchDB in app connect but then a central replication of all the sub databases into a central CouchDB (if needed).

One of the benefits of Couch is that it supports multiple bidirectional replication so databases can take on a tree like structure but this also needs new thinking

3 Likes

Exactly the type of mysql or postgresql db replication I was referring to here in the Server component forum as a Wappler Database Manager extension on CouchDB setup.