Say I want to send an email after a user makes some changes, but I don’t want to inundate them with emails for every single change. I want to ‘batch’ the notifications, so that some amount of time, say 10 minutes, has to pass before the email is sent.
What’s the best way to do this? Use setTimeout on the server? Will this thread effectively?
I think the best way to do this is to save the notifications to your database, then run a cron job to send them on some kind of interval. I wouldn’t save anything in-memory on your server, since then if your code crashes you’ll lose the notification.