I have decided to use CosmosDB in order to store my users permissions data. Our permissions are very dynamic in nature and thus a non relational database makes sense.
For a permission database, it would be very heavy on the query side and low on the write side. My main query would be returning all permissions associated with a particular userId. I have thought of two potential ways of storing my data:
Option 1: Everything under 1 collection
{
"Id": "975808fb-fdd4-47b1-9787-254eb024203e"
"UserId":"9941",
"UserName":"josh.lefebvre ",
"Email":"[email protected]",
"PasswordHash":"XXXX",
"UserPermissions":[
{"ProgramName":"Program1", "Permissions":[
{"Permission":"SavePermission"},
{"Permission":"FirmPermission", "Market": "Chicago"},
{"Permission":"AddPermission", "Warehouse": "Dallas-Warehouse"}
]},
{"ProgramName":"Program2","Permissions":[
{"Permission":"FirmPermission", "Market": "Chicago"}
]}
]
}
Main Drawback is that I don't know what I would use as my partitionkey. However if I had under 100k users would paritioning really make a huge difference?
Option 2: Using 2 Collections Collection 1: Users
{
"Id": "975808fb-fdd4-47b1-9787-254eb0242031"
"UserId":"9941",
"UserName":"josh.lefebvre ",
"Email":"[email protected]",
"PasswordHash":"XXXX",
}
Collection 2: UserPermissions:
{
"Id": "975808fb-fdd4-47b1-9787-254eb0242032"
"UserId":"9941"
"Permission":{
"ProgramName":"Program2",
"Name":"SavePermission",
"Market": "Mexico"
}
},
{
"Id": "975808fb-fdd4-47b1-9787-254eb0242033"
"UserId":"9941"
"Permission":{
"ProgramName":"Program2",
"Name":"FirmPermission",
"Market": "Chicago"
}
},
Main drawback being that there may be 1000s of permissions assigned to a single user which would result in querying a lot of records. However at least I could partition my data correctly based on UserId.
My Question: In terms of the query I am trying to run, get all permissions associated with a particular user by UserId, what would be the best option in terms of performance?