DynamoDB avoids duplication of non-key attributes

I have a custom object with these attributes.

id (key), name and email

And I'm trying to make sure that these attributes are unique in the database.

How to prevent successful put / create / save operation in case of any of the non-key email and name attributes already exists in the database?

I have a tblUsers table, with one key attribute being id . Then I have two globally secondary indexes, each of which also has one key attribute, which is email for the first index table and name for the second.

I use the microsoft.net authentication framework, which itself checks for existing users with a given name or email before creating a user.

The problem that I foresee is the delay between checking existing users and creating a new one. There is no security that multiple threads usually do not create two users with the same name or email.

0
source share
2 answers

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

In your case there are 2 options:

1) force it at the application level - if your security problem, use locks (cache locks)

2) dont use dynamodb (maybe it does not meet your requirements)

+2
source

I use ehcache locally to check for duplicates. Adding another check if ehcache is empty (for some reason the cache was reset). Repopulate cache by executing a request to dynamoDb.

0
source

Source: https://habr.com/ru/post/1243641/


All Articles