mahi-man
mahi-man

Reputation: 4666

Couch DB/Pouch DB replication strategy by user roles

I am designing a mobile app for task management (to-do list plus lots of extra goodies) that can be used offline and sync up when reconnected. I have been impressed with Couch and Pouch DB but am still not sure on the best structure of databases and roles. My situation is that a user can have many tasks and tasks can be shared to many other users (read only) either directly or via assigning a task to a group and then sharing that group with specific users.

After reading through the following question: CouchDB replication strategy with dynamic groups of users I think I may not allow direct sharing of a task and and only allow sharing through Groups. Then each group is effectively a role in Couch which I can then manage authorization to. I can write an API from my web-app so that a mobile user can get a list of groups that are shared to them and then set up a one-way replication from each DB based group to their local Pouch DB. Each user would also have a read and write access to a DB of their own tasks with two way sync from Pouch to Couch. There would be a filtered replication from their own Couch DB to each Role based DB that the task belongs to.

My main questions are:

  1. Is this a valid structure or are there flaws in my logic that would make this difficult?
  2. What would be the best way to handle when a user was removed from a group/role and how to delete any previously replicated tasks on their local Pouch DB now that the Group is no longer shared to them (they no longer have that role)?
  3. A user may delete a group which will mean the entire role based DB will need to be deleted - are the any implications of this?

Upvotes: 3

Views: 1070

Answers (1)

BigBlueHat
BigBlueHat

Reputation: 2365

Great questions, Paul! This seems to keep coming up recently. :)

Is this a valid structure or are there flaws in my logic that would make this difficult?

I think so. I posted an architecture diagram as an answer on a similar mobile-focused (Cordova + PouchDB in that case) workflow.

What would be the best way to handle when a user was removed from a group/role and how to delete any previously replicated tasks on their local Pouch DB now that the Group is no longer shared to them (they no longer have that role)?

Likely the best route is to use a View on the user's database to find all the docs related to the share/group, then use a background process (or some such) to delete those docs (to save space; if you need to).

You could use a bulk docs system in PouchDB or CouchDB with "_deleted": true set on the docs--which should streamline the removal process.

A user may delete a group which will mean the entire role based DB will need to be deleted - are the any implications of this?

Just be sure to also remove the replication tasks to avoid failed replications after the database is gone. Otherwise, you should be fine (as far as I can tell).

Hope that helps!

Upvotes: 1

Related Questions