Search code examples
mqttiot

How MQTT is lightweight when it transports over TCP/IP


In most of IoT platforms, MQTT is used as M2M communication, one of the reasons being lightweight.

Device ---N/W--> MQTT Broker ---> another device

The device communicates to MQTT Broker over TCP/IP, which means there would be a payload addition as part of the TCP/IP layer.

This is my start of confusion: If MQTT runs over TCP/IP, then how come it's a lightweight protocol?


Solution

  • What are you comparing MQTT to?

    The problem with your question is the starting premise to compare MQTT to the underlying TCP/IP that it's using as it's base transport.

    Since MQTT runs on top of TCP/IP it's not a valid comparison, try comparing it to say HTTP (with it's HUGE header) which also runs over TCP/IP.

    Setting up a MQTT connection and then subscribing to a topic is handled in a few bytes + the topic name and the connection is persisted. When a message is sent it again has a couple of bytes of head + topic and the payload.

    By comparison HTTP requests start with the URL + a bunch request headers, the response includes a whole bunch more response headers (there can easily be 100s of bytes of headers as it's all encoded as text) before we get to the payload and in general the connection is closed after the payload.

    If you add in TLS/SSL overheads of starting up a new connection for each payload HTTP get even worse.