I recently had the opportunity to work on a project that required me to architect a mass-notification service for hundreds of thousands of users. The users were part of a social app for sharing book reviews, bookshelves, and everything related to books.
The main challenge was to create a way to send thousands of notifications per second to users subscribed to a favorite author, publisher, or any other object they could subscribe to.
I decided to use AWS SQS, Lambda, and PostgreSQL to keep users' device tokens. In the previous article "Enhancing User Engagement with Push Notifications in Mobile App", I showed you how to create 1:1 notifications. The 1:n approach extends this by adding a middleware Lambda that takes the main event (e.g., an author publishes a new book) and spreads events to all subscribers of the author. The subscribers list is kept in a PostgreSQL table.
The process looks similar to this:
+------------------+
| User Action | (e.g., an author publishes a new book)
+--------+---------+
|
v
+--------+---------+
| Middleware Lambda| (Handles the main event)
+--------+---------+
|
v
+--------+---------+
| PostgreSQL DB | (Fetch subscribers based on the event)
+--------+---------+
|
v
+--------+---------+
| SQS Queue | (Queue to manage notification tasks)
+--------+---------+
|
v
+--------+---------+
| Lambda 2 | (Processes notifications for each subscriber)
+--------+---------+
|
v
+--------+---------+
| Send Notification
+--------+---------+
This setup ensures that the workload is managed efficiently using SQS, and the database operations are handled within the initial middleware Lambda function, enabling scalable and efficient mass notifications.