Im creating an e-commerce backend where each of my products has the following counter attributes
- product views - product likes - product comments count
The current database columns that I have for the product database table,
- id - likes_count - views_count - comments_count - category_id - category_parent_id - category_sub_parent_id - handling_charge - shipping_charge - meetup_address - is_additional_fields - status - is_deleted - created_at - updated_at
As you can see from the next Wanelo engineering blog, the implementation of a counter that can often be updated on one line will lead to blocking the line on innodb, which, if it is updated frequently, can cause deadlock situations in the application. But the solution for this is largely explained on the blog I got an idea about. But what if there are several counters associated with one product that can be updated at the same time as the application grows. How do I create a database table for counters. Do I have to maintain separate tables, namely
likes counter table - id - product_id - count views counter table - id - product_id - count comments counter table - id - product_id - count
By maintaining a separate table, even if a simultaneous update for the product (for example, + comment + view), it will be updated separately and reduces the likelihood of row blocking situations. If it is in the same table, and if updates for all of this occur simultaneously, this can cause a problem.
Question: Is there a better way by which I could create tables for the counter? Any suggestions please?
mysql deadlock counter e-commerce
Ajeesh
source share