Which database structure is better?

Hi there!

I’m still learning and in my practice app there are products as data type which has the following fields:
-name - TEXT
-logo - IMAGE
-description - TEXT
?? (-comment - List of Comments) ??

And comments as another data type has the following fields:
-body - TEXT
-votes - List of Users
?? (-product - PRODUCT) ??

Under each product (on the product page) people can post comments. My question is which approach would be better to structure my database. Comment points to its Product or Product points its Comment?

Comment points to product.

Could you please give me a brief reason why you think this would be the right choice? So I can learn from it.

Depends, in my opinion. If you expect the list of comments to be < 30, then I’d place it as a list under Products. If you expect to have more comments, I’d keep the comments separated from the Product, and place the Product data type under a Comment.

Also, if you expect to display Products on different pages (without its comments), I’d definitely choose the latter approach.

1 Like
  1. Lists are hard capped to 10,000 items
  2. General consensus - if lists can be larger than 100 items => use separate data type cause lists will be less performant
1 Like

So, if I understood correctly, this would be the correct setup?

Data type: Product

-name - TEXT
-logo - IMAGE
-description - TEXT

Data type: Comment

-body - TEXT
-votes - List of Users
-product - PRODUCT

Consider creating a separate data type for the votes since long lists would not be performant as what @artemzheg said

1 Like

I see. And how would that look like?

Data type: Votes
comment - COMMENT
product - PRODUCT

So each vote has its own comment or product?