Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB and User Login table

I've built an application and it currently has a fairly standard user table, as so:

int id, varchar email, varchar password

If I was to switch this to DynamoDB then how would I create this table?

If I use a hash key with the email address, then I'd not be able to offer the ability to update your email and if I used a hash to store the ID, then I'd need to use a scan which is expensive and restricted by a 1Mb limit.

Any advice please? Thanks, Mark

like image 353
Mark Avatar asked Apr 19 '12 13:04

Mark


People also ask

Is DynamoDB good for logging?

DynamoDB is a great choice for logging due to the flexibility and scalability it provides.

Can DynamoDB have multiple tables?

If you store data in two different tables in an RDBMS and frequently join these two tables, you should consider storing them in a single, denormalized DynamoDB table. If not, you're generally fine to separate them if you choose.


2 Answers

Do you say that it would be expensive to use ID as hash because you need to filter by the email field?

If you need to filter your queries by an non-key column, you often ends creating an index for it.

DynamoDB has no built-in secondary index, but is quite simple to implement your own solution.

The main table could use ID as hash, as you pointed, and a differente table would serve as index, it could be:

varchar email, int id

Being email the hash key for the secundary table. If it's allowed to have multiple users with the same email, than you could use ID as range, to make things easier, otherwise a simple column would fit.

like image 157
Rodrigo Ribeiro Avatar answered Oct 21 '22 15:10

Rodrigo Ribeiro


Having a different table for indexing will result in high maintenance. I came across a redundant model from my ex CTO.

For Your table : USER

RDBMS:

id, email password

1, [email protected],asks

DynamoDB:

KEY, id, email, password

1, 1, [email protected], asks

[email protected],1 , [email protected], asks

Instead of storing one record , you are storing redundantly to fetch using non indexed columns.

Hope the solution is clear.

like image 43
senthil3569 Avatar answered Oct 21 '22 15:10

senthil3569