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
DynamoDB is a great choice for logging due to the flexibility and scalability it provides.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With