2

I want to develop chat application and using MQTT and Web socket for live notification, active status at client (mostly web browser). I am wondering that how can I make communication between clients in best possible way to reduce load at MQTT and for smooth communication.

For example, If client A sends a message to client B then options are

1) Make a separate topic for communication between client A and client B

It doesn't look a good idea as if number of clients in application will increase then number of topics between each user will highly increase which will put a load on MQTT broker.

2) Send message on basis unique client Id

MQTT doesn't allows to publish message on basis of client Id

3) Make a single topic for communication among all the clients (all clients will subscribe the topic and relevant client will perform its operation if the message is related to it)

Lots of client will recieve unwanted messages and as the number of clients will grow then it will increase the problem.

In case if all the clients subscribe to a single topic, Is it possible to filter out the client who should receive the message

What can be the other solutions to make a smooth chat application and what solution does other applications use such as slack, telegram, whatsapp etc. Do they also use MQTT and if not then how do they achieve this.

Thanks in Advance

Jayendra Singh
  • 147
  • 2
  • 10

1 Answers1

1

Your understanding for point 1 is flawed.

Topics have nearly zero overhead on the broker. Having millions of topics is not a problem. The only overheads are:

  • The list of topics a client is subscribed to, not really a problem
  • The messages queued for an offline client with a persistent subscription. This is in no way effected by the number of topics, just he number of messages sent to that client while it's offline.

The only processing overhead for a message is checking the list of topics a given client is subscribed to (possibly with a little ACL checking) and then the overhead of actually sending the TCP/IP packets to send that message to the client.

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • 1
    What if I introduce a microservice as a mediator between the clients. this microservice will make connection with each client using a MQTT topic and will act as a middle man. So, Microservice will subscribe to each client topic and persist the messages in database as a message history and if the reciever client is online then it will publish the message in reciever client's topic at the same and if its offline then messages are already in DB. So, whenever reciever will come online it can call API to get the message history. – Jayendra Singh May 18 '21 at 06:11
  • Adding one more client isn't going to change anything – hardillb May 18 '21 at 07:28
  • Microservice client will always be online and once, the browser client are online they can get the older messages from database by calling API in such a way broker will not require to store any information. So, won't remove the overhead ( for the number of messages sent to that client while it's offline) – Jayendra Singh May 18 '21 at 09:40
  • 1
    @JayendraSingh thats really a nice idea until it actually not a end to end chat , privacy issues !! – anshulkatta May 25 '21 at 17:34