Notifications At Scale

Richard La
XP Corp
Published in
4 min readFeb 22, 2021

One of my favourite aspects of being part of an emerging start-up is how every week presents a new series of challenges. With our active Discord community, we’re always finding and working on ways to improve XP Fantasy for our users.

A major improvement that we have recently made was the revamp of our scoring system. Another feature we’ve recently released, which we hope will improve our users’ experience with our platform, is our notifications system.

What Does This Means For Our Users?

As Arjun mentioned in his article, fantasy is much more fun when you can compete against your friends! We wanted to build a system that would let users know when (a) they have received a friend request or, (b) a friend has accepted their friend request, to make the experience for people who want to connect with other users as seamless as possible. Our users can now also be notified when there are important contests starting (shoutout to our user community — thanks to them, we learned that people wanted the option to be notified when contests were starting)!

Designing the Service 🛎

We wanted to design the system to be as automated as possible. In order to do this, we decided that for each microservice we wanted to create notifications for, the individual service would generate notification objects on certain events. These objects would then be ingested by our notifications service which acts as a centralized handler. Instead of using standard REST APIs to send these objects to the notifications service, we opted to push these objects onto a queue (in our case we’re using an SQS queue provided by AWS). The notification service is set up to actively listen to this queue for new objects to ingest. This allows us to truly decouple our microservices. This way, if the notifications service is ever down, we won’t lose any new objects because they’d all still be in the queue until the service is back up and running.

When the service gets a new object from the queue, several actions are performed. First, every object is formatted into a uniform model and then persisted into our database. Then, the object is used to send a notification email to users who are subscribed, (fun fact — the subscribe/unsubscribe functionality is another aspect of the notifications service). The service also keeps track of the last time a user opened the notifications dropdown on the website. You’ll see that this is important for the frontend.

Notification bell with the number of unread notifications

For the notification bell on the website, we can calculate the number of unread notifications to display using the (i) last time a user opened the dropdown and (ii) the time of creation of each notification for that user. When a user clicks on the bell to open their dropdown, the last viewed time is updated, and the number of unread becomes 0. While the dropdown is open, each notification object is formatted into a row. Clicking on any of the rows then takes you to the associated page (i.e. friends, contest, etc.). The default number of notifications loaded by the dropdown is 10 (though I doubt anyone has 10 at the time of writing this article) but, through infinite scroll, more can be displayed.

View of notification bell within the navigation bar

What’s Next ➡️

Currently, only the friends service automatically produces notifications. To notify users of upcoming contests, we use a more manual approach. Since there can be many contests in a day, it would be annoying for users if they got a notification for every single contest. As new services are built out and existing ones are improved upon, we will likely have more services automatically producing notifications (i.e. new badges are available for a user to personalize their profile with, there is some activity in a group the user is part of, etc.). Additionally, if at any time it seems like there’s something that a majority of our users specify that they want notifications for, we’ll always be happy to build it!

With the new notifications system in place, we hope our users will have an even better time competing in daily fantasy esports on XP Fantasy. If you’re interested in what we’re doing, check out our website or join our Discord community!

--

--