Email newsletter w/ tailored content based on user preferences: how to design?

Hi,

I’m looking for resources (or your ideas/approaches!) on designing the architecture of an email notification system based on user preferences. Essentially, think of a job portal: a typical user won’t be interested in all jobs that get posted, but would want to be notified (say twice a week) for any jobs that match his interests (e.g. remote-friendly Elixir jobs based in the GMT+1 timezone).

Job opportunities will get added to the database (through some external mechanism not relevant here), and users need to be notified about new jobs matching their interests, but they shouldn’t be notified more often than their frequency preferences. How should this be approached? My Google-fu is failing me as the combination of keywords I’ve tried invariably bring up help articles on setting email preferences for various websites/software, or newsletter signup info.

One possibility would be to periodically execute (based on the user’s delivery frequency preference) each user’s job selection query against the subset of new jobs having been added to the DB since last execution for that user (merging all result sets if the user has several filter queries), then generating the email with the matches, and enqueueing it for delivery.

You could also periodically (based on some interval) go through all newly added jobs, see which user preferences they satisfy (by running each user query against the subset), and somehow link the matching new results to a “pending” queue for each user. Then, based on the user’s delivery frequency preference, send out the pending items in an email.

Any other approaches, gotchas, etc. I should be aware of? Or better approaches more suitable to Elixir/OTP? I’m sure many similar systems have been written, so it would be great to be able to read up on those before reinventing the wheel and finding out about design/requirement shortcomings the hard way…

Thanks for reading!

I would keep things simple and basically have a scheduler (either Genserver process or quantum, or even a mix script called via cron) that runs every X minutes that will schedule jobs via ecto_job/oban to send emails to users.

Start small and build up.

1 Like

Yeah, the scheduling part should be pretty straightforward. But how would you handle the “match x user constraints to y new data points” part of the problem? Are there any best practices for this?