Defining dynamodb tables the right way


After a liftetime of working with sql databases Im looking into dynamodb and I have a few questions =)

In my sql db I have a company and I have users.

The tables look like this.

Id (autoinccremented), identifier name

Id (autoincremented), identifier, password, name, company_fk

I need to be able to find a company by the foreign key in user.
I need to be able to search company by name
I need to look up a user by its identifier
I need to list users by company
The users might change their identifier (email) but it wont happen often.

In dynamodb would you then create two tables like this.

primary partition key = company identifier (not an autogenerated key but its actual data)
local index on name

Primary key identifier (again not an autogenerated key but its the users email)
Local index on companyidentifier (to be able to list all users for a company)

Or would you give the user a uuid as id and then make another local index on the email. To make it easier to change the iddentifier of the user?


For DynamoDB I would use the UUID as the partition key as this is more random and DynamoDB likes this. (see documentation on partition key) Remember there are some limitations to using a local index, for your example you would probably need a global index. Be aware this is basically just another table which eats from the capacity of your main table. There is more theory to this but I think it’s better if you read the documentation, it’s too much to get it all in this answer.

Another way to solve your problem is to just put the users also in your company table. Remember this is NoSQL, there is no schema. :slight_smile: if you also put the companies into your user table you ever only have to query one table and all the info is just there. I would advise to think about these things when going from SQL to NoSQL, it is not a lift and shift activity. You can get great advantages in NoSQL when you use it’s power but also it can become a great pain when you try to use it as a SQL database.

Sorry if I made it more confusing for you but I really think it’s good if you invest some time in researching NoSQL before you dive in. When you do I am sure you will find it’s a lot of fun, good luck!

Hi Meije.

Thx alot for the answer. Still reading the documentation for dynamodb =)