I have a table which has the amount,entrydate and amtperday field , which is to decrease daily.

so what is better running the cron job daily to decrease amount.


or at the time of fetching data calculate the amount perday with the date field , i can get the no. of day

amount = amount- no.of day * amtperday

so which is good Please suggest ?


First solution (cron):

(+) Database is in consistent state, different clients don't have to know about logic

(+) Performance friendly

(-) Have to have compensation strategy in place in case your cron runs more often or less often than it has to for whatever reason

Second solution:

(+) If the formula for calculation changes often than it doesn't impact the data - can adjust the formula

(-) Performance not friendly (cannot use indexes on calculated fields)

(-) Prone to "copy & paste" of the formula between different clients

Without knowing too much about your situation, I would go with running a daily cron.

  • If you want to go with cron and get rid of the "compensation strategy" you can use manageable schedulers (Quartz, Quartz.Net) and gain control over periodic execution (suspend/reactivate, change execution period etc). – Jacek Prucia Mar 24 '11 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.