DEV Community

Discussion on: eCommerce Database Design

Collapse
 
adhirajk profile image
Adhiraj Kinlekar • Edited

Nice post, Ezzdin! The database design is really good, and I really enjoyed reading this.

Here are my suggestions -

  1. In the context of cart_item and order_item, you probably don't need product_id as it is redundant. The required data can be fetched using product_skus_id.

  2. Storing the total directly in the cart table introduces redundancy, as the total is calculated based on the individual product prices or quantities. This redundancy can lead to data integrity issues. Unless you are using some event-driven mechanism such as database triggers, instead of storing the total directly in the database, you might need to calculate the total dynamically when needed.

Collapse
 
ezzdinatef profile image
Ezzdin Atef

Thank you so much for your positive feedback and insightful suggestions! I'm thrilled to hear that you found the article interesting.

  1. You have a good point about the product_id redundancy, and I will updated the structure with this optimization.

  2. Regarding the storage of the total directly in the cart table, I appreciate your concern about redundancy and potential data integrity issues and instead of that we can calculate the total dynamically when needed, and actually I don’t know much about the event-driven mechanism and will lock into that. Thanks Adhiraj!