I am creating a website that has many products for sale. I need the prices of every product to update based on when they were posted.
For example I have a product posted today at 12:04PM. What I want, is for the application to change the price every day at 12:04PM.
I understand that a CRON will do that, however I am just trying to figure out if the server will take a toll trying to updated every price in the database.
My best guess will be to write the cron every minute and pull the products that match the time and then update them.
Will every minute be a huge issue? Or does anybody know of a better way? Also I am expecting to have a lot of products, i would say over 200k if not more.
The logic of updating product the minute they were created does not make any sense to me, could have bucketed discretely. However, even if you have 200k products ( as an example) and want to run cron every minute ( every minute is not that bad only 1440 additional requests per day), assuming an uniform distribution its 200k divided by 1440 = ~139 products per minute ( not that bad).
A big HOWEVER, do make sure that the database remains in a consistent state when this is happening...
Probably much better to have the price changing logic build into the application rather than updating it in the database.
Presumably there is some sort of formula that is used to determine the price given the original price, the created date, and the current data.
You can add a function to the model called something like getCurrentPrice or something that would calculate this and return it. Then use that price rather than the value stored in the database.
As new shipments are ordered a price fluctuations per shipment are common I set a price table that's accociated with a product.
In the price table I keep a quantity and sold integers along with time stamps and price maybe a threshold.
If the quantity is not 0 I show that that price. On some instances where it maybe more common for an item to have many purchased at once you can set another column as a threshold. So if quantity is less the threshold show the other price if higher. Etc.
This also allows easier output if what items sold at what price.
Setting a basic product or item table fails at this with out it becoming large and over complicated with what ifs and maybe more importantly more dynamic so you can update stuff via web versus code.