1
votes

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

1

1 Answers

1
votes

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.