Search code examples
asp.netamazon-web-servicesasp.net-mvc-5asp.net-identityamazon-dynamodb

DynamoDB avoid duplicate non-key attributes


I have a user object with these attributes.

id (key), name and email

And I am trying to make sure these attributes are unique in the DB.

How do I prevent a put/create/save operation from succeeding, in case of either of the non-key attributes, email and name, already exists in the DB?

I have a table, tblUsers with one key-attribute being the id. I then have two globally secondary indexes, each with also one key-attribute, being the email for the first index-table, and name for the second.

I am using microsoft .net identity framework, which itself checks for existing users with a given name or email, before creating a user.

The problem I forsee, is the delay between checking for existing users and creating a new. There is no safety, that multiple threads wont end up creating two users with the same name or email.


Solution

  • dynamodb can force uniqueness only for hash-range table keys (not for global secondary index keys)

    do in your case there are 2 options:

    1) force it on application level - if your problem is safety, then use locks (cache locks)

    2) dont use dynamodb (maybe its not answer your requirements )