I'm writing a simple notification service i Go. The service provides a REST api where one can put notifications, for instance
{
delayUntil: '2016-02-05T18:00:00'
user: 'username',
msg: 'Hello World',
isSent: false
}
Now I would like to send a notification to the user at time delayUntil with the requirement that the service should work even if it restarted which means I have to persist the notification. Right now I'm using BoltDB (key/value store).
One way to solve this is to continuously read the DB and send a notification where the delayUntil has passed.
Another way could be to read the DB on service start, and put each notification in a goroutine which fires at the delayUntil time. After the message has been sent, it is marked as Sent in the DB. New entries coming in to the API are inserted into the DB and scheduled.
Is there a preferred/better/simpler way to achieve this?
Edit: Only one instance is required.