recommendations for writing a simple & scalable notification system?

i'm working on a blog/forum site & about to start on a simple notification system that sends out notifications to followers when an author publishes a post i was thinking of just creating a little temporary store in my database, creating a notification document with a unique in it, & then appending the id of that document into a follower's notifications list in code i guess it would look something like
app.post("/", (req, res) => {
let post = new Post;
// ...
await post.save();

let notification = new Notification;
// ...
await notification.save();

// a queue is definitely more scalable, but just sticking this here to get the point across
await Users.updateMany(
{ "_id": { "$in": req.user.followers } },
{ "$push": { "notifications": notification._id } }
).exec();

return res.send("ok");
});
app.post("/", (req, res) => {
let post = new Post;
// ...
await post.save();

let notification = new Notification;
// ...
await notification.save();

// a queue is definitely more scalable, but just sticking this here to get the point across
await Users.updateMany(
{ "_id": { "$in": req.user.followers } },
{ "$push": { "notifications": notification._id } }
).exec();

return res.send("ok");
});
as stated in the comment above updateMany, i've been thinking about writing a queue to schedule these notifications in batches so that my endpoint doesn't bottleneck & kill the server but as i think about it, if the amount of users dramatically scales up, would the only other option be to use a dedicated server/service for notifications? there are just a lot of questions floating around in my head when it comes to scaling the system for potentially hundreds of thousands of users if you guys have any recommendations or experience, please let me know asap 🙏
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server