

Ask HN: What algorithms do you use to handle time based event? - lasryaric

Lets say you are writing a program that should send notifications at a user defined date.
For example, a tasks management application should send notifications at the due date of the task, defined by the user.
Any date can be inserted at any time in the list of &quot;notifications&quot; to send.<p>What algorithms would use? The best answer to that question was for me to use a priority queue.<p>I am curious to learn about alternative to that problem.
======
greenyoda
A priority queue is usually an in-memory data structure. However, if you want
to be able to schedule notifications in the distant future (e.g., a week or a
year from today), you're going to need a stable and reliable way of storing
them that can survive server re-starts, such as a database. Once your
notifications are in a database, you can just run an SQL query that will
select all the unsent notifications whose due date is between the last query
time and the current date/time (after which you mark them as 'sent' or delete
them). You'd want to have an index on the date/time field to allow for
efficient retrieval.

