I'm building a reservation system in Rails 4.2 where I need to send a set of emails to users at predefined intervals (for example that they have an upcoming reservation, feedback after it's done, a link to change/cancel an existing reservation, etc.). I've looked around and found this and this, but I'm trying to decide between the approaches.
I see two main ways of building this system out.
Using a queue system like delayed_job. Whenever someone makes a reservation, we queue up all the emails for the correct time when they should be sent.
Pro: One queue for all emails. Automatic retry logic.
Con: Thousands of emails will eventually get queued in the system. Need to dequeue whenever someone cancels a reservation (dependent: destroy emails related to it might be pretty easy). Somewhat more complex logic around what time we need the emails to go out.
cron
+ rake
task that runs at some predefined interval (hourly? every fifteen minutes?) and checks for the emails that need to go out. It runs a query like "Find all reservations that are three days from now", and then sends out all emails.
Pro: Put everything into application logic, reduce the amount of state we need to keep track of.
Con: Need to keep track of which emails have been sent, which is conceptually similar to whatever jobs table we already have created above.
Second approach is better (use heroku scheduler if on heroku), queues are more for "run as soon as possible" than "run at this particular datetime"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With