Modelling recurring events

by Vektor88   Last Updated November 10, 2018 13:05 PM

I am in the process of writing a web app to track expenses and which will be multiuser.

Everything is fine with a single expense, but I am struggling to find the best way to represent recurring expenses, i.e. expenses of the same amount and category that repeat regularly until cancelled.

I am thinking to model recurring expenses as an instance of a more generic ExpenseGenerator which as properties has a starting date and a frequency pattern, which then will automatically create one or more Expenses, beginning from the starting date of the generator.

Given that this approach is correct (if not, please suggest some other options), I am unsure about how to trigger the creation of the expenses. Should I create something like a cronjob that creates the new expense as soon as it occurs or check the generator status every time a user does the login?

Both the solutions have some concern point:

  1. Cronjob: this will create a job for each existing expense of each existing user, plus I should deal with different time zones, daylight savings time and so on.
  2. Creation at Login: if the user does not log in for a long period, there might be a lot of expenses to be created.

Am I going in the right direction or is there a more efficient approach to model recurring events and solve all these problems?



Related Questions






Ubiquitous language and resource based REST API?

Updated June 15, 2016 08:02 AM