问题
I am making a SaaS application in which users will create advertisement listings.
- All advertisements should be visible to all users of my registered users as well as unregistered visitors
- Only registered users can create an advertisement
- A registered user can create several advertisements
- Only the user who creates the advertisement should be able to delete or edit it.
I have never done user and data management w.r.t. a database so I need advice on how I should implement it (I acknowledge that this is an open question but I still feel it is relevant as where else could I ask!!)
My database is cassandra
.
- I am thinking of using a single keyspace for all the advertisements to address point#1
- I am thinking of creating a dedicate keyspace for each user where their advertisements will be stored (point#2, point#3 and point#4).
- If a use edits/deletes an advertisement then the user-specific keyspace and the global keyspace for all advertisements would need to be changed
Question 1 - Is my approach the usual way of creating such an application? If not, I'll appreciate suggestions on alternate designs.
Question 2 - As I'll create user specific keyspaces, would I be able to programatically create a keyspace (with user's provided username and password) as part of my web signup process?
回答1:
It's not good idea to have per user keyspace in Cassandra, this will work only if you have a couple of users. The individual keyspaces will mean that you're creating a separate tables for every user, so it will contradict the point 1 - to show all advertisements you'll need to read from all of tables. And Cassandra also has limitations on number of tables that it can support - recommended values are not more 500 tables in cluster (see this answer for more details).
I recommend just to put user ID as a part of the partition key, or partition key itself - but this will depend on the other factors, like, how many advertisements can user create, etc. - this requires a separate question.
I suggest to take DS220 course on Cassandra data modelling at DataStax Academy just to get better understanding how to model data for Cassandra.
来源:https://stackoverflow.com/questions/57285428/how-should-i-implement-data-access-rights-management-in-cassandra