1

I am developing a MQTT service and I am confused when I design the topics. I think there are two ways to do this:

  1. Topic data/customer-a

    Payload {"sensor-id":"23aafff2d23659cc97c557909de12f16","type":"demo","value":"hello world"}

  2. Topic data/customer-a/23aafff2d23659cc97c557909de12f16

    Payload {"type":"demo","value":"hello world"}

I wonder which is better. I think the first one may result in complexity when I need to subscribe message from a single sensor. Meanwhile, the topic data/customer-a is always under heavy load because of thousands of messages per second. And the second one has drawbacks too, obviously it makes the mqtt broker maintain a huge topic tree, I don't know whether it would cause significant performance degradation?

Which is better for thousands of devices of multiple customers?

Ming Lv
  • 11
  • 3
  • With option 1 you cannot "subscribe message from a single sensor" at all (you can subscribe to all messages for a customer and then filter the messages received). "the mqtt broker maintain a huge topic tree" not really; when a message arrives its queued for delivery to subscribed connected (and possibly disconnected) clients (see [session state in the spec](https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901230) for info on what info needs to be held). I'd tend towards 2 but it really depends on your requirements. – Brits Jun 16 '22 at 05:19
  • @Brits thx a lot for your reply. Did I misunderstand the vernemq document? Please refer to [mountpoints specification](https://docs.vernemq.com/configuring-vernemq/listeners#mountpoints). – Ming Lv Jun 16 '22 at 05:41
  • That looks like a Verne specific add-on (as the document says "Normally an MQTT broker hosts one single topic tree"). I can see that being useful if you run a broker as a managed service (more than one customer may use the `test` topic and should not see each others messages) but it would probably unnecessarily complicate things in your use-case (you control the topics and can use ACL's to limit customer access). – Brits Jun 16 '22 at 05:51

1 Answers1

0

There is no real overhead to a broker "maintaining a massive topic tree" because they don't.

The only thing the broker tracks is the list of subscription patterns that each client has active, it then checks that list every time a message is published.

hardillb
  • 54,545
  • 11
  • 67
  • 105