0

I want to make an app which lets users comment and send messages. However, the notifications for these events will have to come instantly, just like any other social-media or chat application. This is what I'm thinking of:

  1. Web-frontend: Angular, mobile: Ioinc with Angular
  2. Backend: Node, Mongo

Now, this is how I was thinking I'd implement real-time notification.

  1. There's a constant socket connection between the frontend (web & mobile-app) and the backend.
  2. Whenever a message arrives, targeted to a specific user, I'll use some kind of a Mongo-hook to send the notification to the frontend via the socket connection.

Now, the confusion with this approach is:

  1. Would millions of socket connections work at scale, at all? If not, what is the way to implement this pub-sub kind of system? I need to do it from scratch, not using Firebase.
  2. What if a user is offline when he receives the message in the backend? If the socket is not on, how would he get the message? Is there a way to do it using Kafka? Please explain if you have some ideas on this.

Is this the correct approach? If not, can you suggest what would be appropriate?

1 Answers1

0
  1. Would millions of socket connections work at scale, at all? If not, what is the way to implement this pub-sub kind of system? I need to do it from scratch, not using Firebase.

Yes, it can work at scale just you have to made an architecture like that. You might find this useful

  1. Scalable architecture for socket.io
  2. https://socket.io/docs/v3/using-multiple-nodes/
  1. What if a user is offline when he receives the message in the backend? If the socket is not on, how would he get the message?

If he the socket is not on or user is offline, then client Socket will be disconnected. At this point, notification will not be received and whenever the user comes online you'll have make an API call to get the notifications and connect again to the socket for further operations.

Is there a way to do it using Kafka?

Yes, you can also do it with Kafka. You'll need Consumer API(Subscriber) and Producer API(Publisher)

https://kafka.apache.org/documentation/#api

https://www.npmjs.com/package/kafka-node

Sending Apache Kafka data on web page

What do you use Apache Kafka for?

Real time notification with Kafka and NodeJS

Abhishek Pankar
  • 723
  • 8
  • 26