Updating mysql table frequently. Can it cause performance issue?

Hello there!

Just wondering if updating a table frequently can cause performance issue?
Let’s say I have a website where users can upload hundreds of products daily and I want to track the popularity (views) of each product.
And lets assume that hundreds of thousands visitors browse the website daily.

If I do this by updating the rows in the product table (e.g. SET p_views = p_views + 1) when a visitor clicks on the product page, will it be okay?
Maybe I can limit the updates with a SESSION variable so it will only update the row when the visitor clicks on a product and blocks the update if the user refreshes the product’s page constantly.

You, can always check if $_SESSION['viewed_items'] holds the product ID and if not, make the update. Something like this.

if(!isset($_SESSION['viewed_items'])){$_SESSION['viewed_items'] = array();}	
	//Make Update
	$_SESSION['viewed_items'][] = $product_id;

Yeah, I had something similar in mind!

So you say if I have 100.000 visitors daily who view 50 product in average (hence makes at least 5 million updates) will not slow down the database/website?

It’s not like you are making 5 million new records every day, you are just updating a views field so you should be fine.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.