MQTT vs HTTP Comparison: Which Protocol is Best for IoT?

Ngày xuất bản: 5 tháng 6, 2023

HTTP is the most popular and widely used protocol. But over the years MQTT quickly gained credibility in the IoT market.
IoT application developers are having to choose between these two protocols HTTP or MQTT.

1.Design and package

MQTT is data centric while HTTP is document centric. HTTP is a request-response protocol for client computers and is not always optimized for mobile devices. The main benefits of MQTT are compactness (MQTT transfers data as a byte array) and publisher/subscriber model, making it perfect for resource-constrained devices and helping to save energy.

Besides, the publisher / subscriber model provides customers with independent existence and improves the reliability of the whole system. When one customer is inactive, the entire system can continue to function normally.

2.Compare the speed of 2 protocols MQTT and HTTP

According to measurements in 3G networks, the throughput of MQTT is 93 times faster than HTTP.

In addition, compared to HTTP, the MQTT Protocol guarantees the highest quality of delivery.

There are 3 levels of Quality of Service (Qos):

  • at most once (QoS = 0): ensure the best information delivery.
  • at least once (QoS = 1): ensures that a message will be delivered at least once. But the message can also be sent more than once.
  • exactly once (QoS = 2): ensures that each message is received only once by the counterparty.

MQTT also provides users with options for final and retained messages. This means that in the event of an unexpected client disconnection, all subscribed clients will receive a message from the broker.

Retained messages mean that a new customer subscriber will receive an immediate status update.

The HTTP protocol does not have these capabilities.

3.Message complexity and size

MQTT has a pretty short specification. Only the CONNECT, PUBOUND, SUBSCRIBE, UNSUBSCRIBE and DISCONNECT types make sense to developers. While the HTTP spec is much longer.

When comparing the message size between MQTT and HTTP : MQTT has a very short message header and the smallest packet message size is 2 bytes. Using the text message format using the HTTP protocol allows it to compose long headers and messages.

This eliminates the hassle as it is human readable, but at the same time, it is not necessary for devices that are resource constrained and only need to pass binary parameters.

The following table compares the MQTT and HTTP protocols.

Features and characteristicsMQTTHTTP
Complete formsMessage queuing remotelyHypertext Transfer Protocol
Design methodProtocol is data centerProtocol is the central document
ArchitecturePublisher / Subscriber: Here devices can publish any topic and also subscribe to any updated topic.Request/Response
ComplexitySimpleMore complex
Data securityHaveNot yet secure, so HTTPS is used to provide security
Upper layer protocolRuns on TCPRun on UDP
Message sizeSmall, binary with header taking up 2 BytesBig, in ASCIILarge format, print ASCII format
Service Levels (QoS)31
Library30KB C, 100KB JavaBig
Port188380 or 8080
Data partition1 to 0/1/None to one

3.Conclusion

The MQTT protocol is very easy to use, responds well to unstable connection conditions, and low bandwidth. This makes MQTT very suitable for IoT applications.

Thông tin liên hệ

  • 0387 430 957
  • pambu@DHG.asia
  • Ô số 24, lô V5A – Khu nhà ở thấp tầng, khu đô thị mới Văn Phú , Phường Phú La, Quận Hà Đông, Thành phố Hà Nội, Việt Nam

Giờ làm việc

Thứ Hai - Thứ Sáu: 8:00 - 17:30
Thứ Bảy: 8:00 - 12:00

Copyright @ 2022 Pambu.org