2

In a simple calendar application, I'm particularly interested in understanding the pros/cons of storing recurring events versus calculating them. I have a list of what I feel are the pros/cons of each, but I'm curious if anyone has experience and might be able to provide me with more definitive reasoning for one way or the other

Storing

Pros

  • Read efficiency (dates in a date range is a single, indexed query)
  • Easily handle overrides (simply update a single item)

Cons

  • Requires a process for calculating and storing future events (how far forward to go?)
  • Expensive to make changes that affect all events (have to update all rows - write heavy)
  • More data

Calculating

Pros

  • Nothing to keep in sync
  • Efficient writing of events (drop a single entry in a table)
  • Less data

Cons

  • Expensive to generate a calendar for a timeframe (have to select all single instance events, then all recurring events that could possibly overlap, then calculate recurrences to determine if any of them actually do overlap)
  • More difficult to handle exclusions/overrides (specify an override date for the recurring event, then add a separate single event for the date to change

In general, the list above seems to point towards calculating, which I think makes sense for a single user/few user system. Would the decision change if the system were to be scaled out to, say, an Exchange server hosting 10k+ users and their calendars?

1
  • What about approaching the subject from this side; How many events can a single user hold ? 100, 1000, 10 000. I still insist on calculating the recurrences. But it would be good if you log events well for reliance. Sep 10, 2014 at 6:55

2 Answers 2

1

It seems you've already summarized the pros and cons . Maybe combination of them would be more effective.

If I were you I normally calculate it, it is most cost efficient in operational and bulk-data-management aspects. Then I store excepitonal ones. Thereby we can say in our UI "Would you like to change this one as well ?" If our answer would be No we still just change the rule. Otherwise we should change the rule but also the exceptional record. This would be the most cost effective stuff in our design but this is a tradeoff.

  • Keeping the rule
  • Supporting variety for exceptional ones
  • Avoiding mass transactions

But we still have lots of things to do :) This is why people still employ us.

2
  • You don't think that calculating them would become too expensive as a user's list of events continues to grow over time?
    – Colin M
    Sep 8, 2014 at 11:37
  • As far as I considered this is a tradeoff. As you said each one has side effects. This is my preference because I don't want to track millions of records on db. Today's PCs are extremely powerful. This is a way of exploiting from their hardware in a true way. Instant changes for rules and isolating the particular ones for reliance. Sep 8, 2014 at 12:55
1

This would be an ideal case to use a primary store to store your event and a secondary store like redis or memcached to store your recurring events.

The first time an event's recurrence is calculated you will push the data onto your secondary store. From then on its just a query to redis to get your data. In case of an update to the event, just drop the keys. They next time you shoot a query you will find that its not there in redis and repopulate the data. This way you don't have to do any expensive updates. The price you pay is like any cache solution where your first computation will be expensive.

This would address the first 2nd and 3rd cons of storing.

  • Requires a process for calculating and storing future events (how far forward to go?)
  • Expensive to make changes that affect all events (have to update all rows - write heavy) ( Redis is blazing fast, ~60K writes a second)
  • More data (Shall i call it meta data ? and its just in your secondary cache store)

The first issue, requires a process for calculating and storing future events Thats heavily coupled to the business logic. Maybe it can be solved without even having to calculate these dates ? To be honest I don't understand the use case fully so I don't even know if its necessary to calculate and store the recurrence in the first place.

But on the whole go ahead and store it in your favourite secondary store. This data does not belong in your traditional RDBMS or Document data store.

1
  • In general, it seems like the consensus I'm hearing is to calculate the events. Your answer hints at the same, extending upon it to also cache the calculated objects out to some point in time. I'm mostly worried about things like birthdays that could add up to quite a few events, and will rarely be removed from one's calendar.
    – Colin M
    Sep 10, 2014 at 2:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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