I am creating an ASP.NET MVC application with Identity and I decided to go with Azure Table Storage since it's very cheap and fast for my needs. The application will have two types of accounts: single user and multi-users with one owner. So I modeled this:
public class User : TableEntity, IUser
{
/// <summary>
/// The Email of the owner of the account
/// </summary>
public string Id { get { return PartitionKey; } set { PartitionKey = value; } }
/// <summary>
/// The Email of the user of the account
/// </summary>
public string UserName { get { return RowKey; } set { RowKey = value; } }
//other fields not relevant
}
I am wondering how to make this effective for logging in and searching for a user, however. The Store for Identity has this:
public async Task<User> FindByIdAsync(string userId)
{
try
{
TableResult operation = await UsersTable.ExecuteAsync(TableOperation.Retrieve<User>(userId, userId));
return operation.Result as User;
}
catch (Exception)
{
return null;
}
}
If the user trying to log in is the owner of the account, this will be a Single Point query and, according to the docs, have the best performance.
However, if the user is not the owner, that would result in a full table scan since a PartitionKey would not be available to filter on it, so the query would have the worst performance.
The other idea I have would be to make the user the PartitionKey and the owner the RowKey, but that would make it every single search a Range Query and have less performance than the Single Point queries.
How could I best design this? This is a new app, so there is no existing user base.
Id
? Is it some value that uniquely identifies a user or is it some value that identifies the account? 2) What's the format of this Id? Is it a GUID value or something that user specifies (like a login name)? 3) How are the users authenticating themselves in your application? Do you have your own user store where users are authenticated by username/password or have you implemented some kind of external identity store like Azure AD/Microsoft Account etc.? 4) How do you differentiate between a single user & multi-user? – Gaurav Mantri