Reputation: 121
I am working on a project where users can have "items" (like an inventory system).
Those items have a structure similar to:
item : {
id: "00000000-0000-0000-0000-000000000000", //uuid
name: "Item Name",
description: "Lorem ipsum dolor sit amet, consectetur adipiscing ..",
image: "image.jpg_00000000-0000-0000-0000-000000000000"
}
The main concept is that those items will be created by users (the first user to use it will create it, and then it will be available for other users).
In a traditional SQL DB schema, I would create something like this:
ITEMS:
id | name | description | image |
---|---|---|---|
00000000-0000-0000-0000-000000000001 | Item 01 | Lorem ipsum dolor sit amet, consectetur adipiscing .. | image.jpg_0000-0000-000000-001 |
00000000-0000-0000-0000-000000000002 | Item 02 | Lorem ipsum dolor sit amet, consectetur adipiscing .. | image.jpg_0000-0000-000000-002 |
00000000-0000-0000-0000-000000000003 | Item 03 | Lorem ipsum dolor sit amet, consectetur adipiscing .. | image.jpg_0000-0000-000000-003 |
USERDATA:
username | id | date | amount | another Field |
---|---|---|---|---|
example01 | 00000000-0000-0000-0000-000000000001 | Date.now() | 1 | "Abc" |
example02 | 00000000-0000-0000-0000-000000000001 | Date.now() | 5 | "Def" |
example01 | 00000000-0000-0000-0000-000000000002 | Date.now() | 3 | "Ghi" |
Since I want to use DynamoDB (NoSQL), I'm not sure how should I organize the DB. *
After reading several documentation and posts, I have seen that the main idea of NoSQL is to avoid splitting data into different tables. Even some information says that sometimes is better to have duplicate data, I don't think that creating the object for every instance is a good solution.
In my mind, I have something like this, even I'm not sure if this is how is supposed to work DynamoDB:
id | name | description | image | username | date | amount |
---|---|---|---|---|---|---|
0000000.. | Item 01 | Lorem ipsum .. | image.. | Example01 | Date.now()+x | 3 |
Example02 | Date.now()+y | 15 | ||||
0000000.. | Item 02 | Lorem ipsum .. | image.. | |||
0000000.. | Item 03 | Lorem ipsum .. | image.. | Example01 | Date.now()+z | 1 |
How should I structure my DynamoDB in this case?
Question Update after reviewing both videos listed on the first answer:
I have to say that after reviewing both videos, I clearly understand much better the whole process of how I should design my DB.
First of all my Access Patterns are these:
The problem is that I haven't seen any example where the "items list" is treated on the table. For example, in the examples of the videos, the users have "orders" and these "orders" have "items".. But it is not shown how to "store" the items.
If the items would be only "id" and "name", there would not be any problem to store them every time inside a DynamoDB item ("row"). With this, we would have problems if the item ever changes the name, but this would be possible to fix with a simple script.
The problem comes, when the items have more fields (for example, "description", that can be larger). In this case, I'm not sure that would be good to save the entire item every time.
* It's a personal project, where the main objective is to learn some "technologies". I know in this case would be easier to use a SQL DB.
Upvotes: 1
Views: 813
Reputation: 5747
The answer to "how should I structure my data in DynamoDB?" will always depend on how you intend to access the data. For example, consider the following use cases:
In DynamoDB, we store our data based on how our application needs to access the data (aka "access patterns"). Each of the access patterns I've outlined above may have entirely different data models. Thus, it's difficult to answer the question "how should I model my data" without knowing what you are trying to do with the data.
The best way to start learning about DynamoDB data modeling is to watch this talk by Alex Debrie. In under 45 minutes, he describes DynamoDB fundamentals and gives several data modeling examples (one-to-one, one-to-many, etc).
DynamoDB requires you to think critically about your application's access patterns ahead of time. So, what are you trying to build?
Upvotes: 3