views:

36

answers:

2

We are developing and web application which allows users to register for certain events. What application is supposed to do, is to send them few notifications to remind them that they have registered. There will be more than 1k user which can register for many events in very wide time range. We have to send notofications like 3 months, 1 month, 1 week and one day before event.

The first thing is that I have to determine if I need to send notification to a specific user.
I'm thinking about thread which will iterate over registrations and determine whether sending notification is required or not. If notification is required, should I do it right away or maybe put all of the objects that need it in some kind of cache and then send them (by another thread)?

Second thing is: if I made that thread - is better to put it and run next to application or embed that thread into application and, for example, start it in the context listener?

How You would solve this? Maybe there are better approaches?

+1  A: 

Tabling the question about how to schedule the notifications once they're identified, I'd recommend looping over upcoming events, instead of over all users. It seems very likely that you'll have many more users than events (especially if you limit your scan to events that happen exactly 1 week, 1 month and 3 months in the future).

As far as the notifications, I think marking notifications to be sent first, then processing all the marked notifications will allow for more optimization than sending out notifications as part of your scan. If you have a queue of notifications to be sent out, you could then send each affected user one email including multiple events in the same time.

zigdon
+2  A: 

I would not spawn my own threads for that, I would use a scheduler like Quartz and run daily or hourly jobs (I don't know what granularity you need) that would:

  1. find upcoming events in 1 day, 1 week, 1 month, 3 months and users that should get notified about them.
  2. create the notifications and send them

I would probably implement that using separate jobs (sending notifications is a different concern) and thus queue the results of the first part, this will give you more flexibility. And the first part could be done by a unique job scheduled with different time frame parameters (1 day, 1 week, 1 month, 3 months).

Pascal Thivent
time intervals between notifications can be added or modified so I think one job should run every N (where N is the lowest interval). User only gets information that he has event then and then. But I like the scheduler approach - I didn't even know such service exists ;)
jjczopek
@jjczopek There are some other options to schedule Java jobs but if you're looking for a robust solution with fail over, etc, Quartz is definitely the way to go.
Pascal Thivent