TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

1 pointsby lasryaricabout 10 years ago
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.

1 comment

greenyodaabout 10 years ago
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&#x27;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&#x2F;time (after which you mark them as &#x27;sent&#x27; or delete them). You&#x27;d want to have an index on the date&#x2F;time field to allow for efficient retrieval.