Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ?

share|improve this question
up vote 0 down vote accepted

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.

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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