I am wondering about best practices of topic naming and payload design of mqtt messages.

Is it better to have multiple and long topic names instead and a bigger payload or short topic name with bigger payload.

For example:

plant1/machineA/sensorX/temperature/value 20
plant1/machineA/sensorX/temperature/unit C
plant1/machineA/sensorX/temperature/timestamp 2018-08-01T12:00:30.123Z


      ["sensorX": {
       "value": 20,
       "unit": "C",
       "timestamp": "2018-08-01T12:00:30.123Z"

There are a lot more possibilities. But is there a general approach? As much as possible in topic name or in payload?

  • 1
    It totally depends on your use case.
    – hardillb
    Commented Aug 16, 2018 at 15:14

2 Answers 2


Your design question is that of a protocol on top of the MQTT transport. There are existing protocols that can guide your choice:

The choice for topic endpoints for high-scalability applications seems to be a small set of topics per thing (makes sense: if you have millions of things, you want to minimize the switching burden on the broker), at least one "event" topic (where telemetry is published from thing to application) and one "control" topic (where commands are received from the application by the thing).

Further, the information in the payload usually consists of a key (eg. timestamp or sequence number) and values for attributes. In your first choice, how do you tie together the different values received on different topics in the face of unsynchronized message streams over your network?


The decision should be made based on how are you using topics. If you need values together - post them into one topic, if you are using separately - put them into separate topics. Also do not post values, like in your first sample, in the topics. And do not create exceed topics, like sensorX/temperature for temperature sensors, go from more general in the beginning to more specific in the end. So I would recommend you to post into:

   "value": 20,
   "unit": "C",
   "timestamp": "2018-08-01T12:00:30.123Z"

or if you have various types of sensors and want to select between them put temperature somewhere before sensor name:


or also possible case is:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.