Skip to content
Home › SQL Comparisons › Kafka vs MQTT
Comparison · Time-Series & IoT

Kafka vs MQTT

Kafka and MQTT are not substitutes. MQTT is a lightweight publish/subscribe protocol that devices use to talk to a broker over constrained or unreliable networks; Apache Kafka is a distributed event streaming platform that stores streams of events durably in partitioned, replicated topics for many back-end consumers. In IoT systems they are usually chained: devices publish over MQTT, a bridge moves messages into Kafka, and consumers write to databases. Neither one is a database.

Last verified October 2026. Versions checked: Apache Kafka 4.4.0, MQTT 5.0 and 3.1.1 (OASIS standards). Licensing and features change; check the official sources for the latest details.

Quick verdict

Short answer

Our editorial view, based on the documented roles below: use MQTT at the edge: sensors, controllers and gateways publishing readings and receiving commands over cellular, Wi-Fi or site networks, with small client libraries, quality-of-service levels, retained last values and last-will messages. Use Kafka in the back end when several systems need the same stream (a time-series database, a CMMS rule engine, a data lake), when you need to replay history after a bug or outage, and when ingestion must keep going while a database is down. Many building and industrial platforms use both, joined by an MQTT-to-Kafka bridge. Small deployments often need only an MQTT broker and one subscriber that writes to the database.

How we know: This comparison is research-based: the roles, delivery guarantees, storage and retention behaviour, consumer model and security options were checked against the Apache Kafka 4.4 documentation (including the upgrade notes for the share group status and the Kafka Connect overview, which does not mention an MQTT connector) and downloads page, mqtt.org, the OASIS MQTT Version 5.0 specification, the Eclipse Mosquitto repository and the RabbitMQ MQTT plugin guide on 27 October 2026. The PostgreSQL idempotent-insert example was run on PostgreSQL 18.6 (PGlite 0.5.11). No Kafka cluster or MQTT broker was run for this page, and we have not run benchmarks, so no throughput or latency figures are given.

This page is for architects of building management, CAFM, CMMS and industrial IoT systems who see both names on a reference architecture and want to know which does what. A typical example: a BMS gateway reads AHU supply-air temperature, chiller kW and zone CO2 every 1 to 60 seconds from BACnet or Modbus, publishes them, and the readings must reach a time-series database, an alarm service that raises maintenance work orders, and a long-term analytics store. For the full data path from devices to dashboards, see the time-series and IoT data hub.

MQTT is an OASIS standard messaging protocol. The specification describes it as a client-server publish/subscribe transport that is light weight and simple, intended for constrained environments such as M2M and IoT. Versions 5.0 and 3.1.1 are OASIS standards (3.1.1 is also an ISO standard). MQTT is a protocol, not a product: you run a broker such as Eclipse Mosquitto, the MQTT plugin in RabbitMQ, or a commercial or cloud broker.

Apache Kafka is an open source event streaming platform from the Apache Software Foundation. Its documentation lists three capabilities: publishing and subscribing to streams of events, storing them durably for as long as you want, and processing them as they occur or retrospectively. The latest release when checked was 4.4.0 (22 October 2026). See the Apache Kafka guide for architecture detail.

Side by side

AspectApache KafkaMQTT
What it is Distributed event streaming platform: brokers, clients, Kafka Connect and Kafka Streams Messaging protocol (OASIS standard); implemented by brokers and client libraries
Typical clients Back-end services, stream processors, connectors to databases and lakes Sensors, controllers, gateways, mobile apps; small client footprint
Message model Events appended to partitioned topics; each event has a key, value, timestamp and headers Messages published to hierarchical topic names; subscribers use topic filters with + and # wildcards
Storage after delivery Events are kept for the topic's retention period (default 7 days) whether or not they were read No history in the protocol: the broker forwards messages, keeps queued messages for persistent sessions and one retained message per topic
Replay Consumers can rewind to an earlier offset and re-read Not part of the protocol
Delivery guarantees At-least-once by default; idempotent producer and transactions give exactly-once processing only from Kafka to Kafka; a database sink needs its own safeguards QoS 0 at most once, QoS 1 at least once, QoS 2 exactly once (per hop, broker support varies)
Ordering Guaranteed within a partition; events with the same key go to the same partition The specification defines ordering rules per topic for a client session; there is no partitioning concept
Scaling consumers Consumer groups split partitions between instances; share groups (production-ready since Kafka 4.2) for queue-style work Shared subscriptions (MQTT 5.0) spread one subscription across several sessions
Device features None specific to devices Last Will and Testament, retained messages, keep-alive, persistent sessions
Licence Apache License 2.0 Open standard; brokers have their own licences (for example Mosquitto is an Eclipse open source project)

Key differences

Different jobs: device messaging versus an event log

MQTT solves the device problem. mqtt.org describes it as designed for constrained devices and low-bandwidth, high-latency or unreliable networks, with small headers to save bandwidth and persistent sessions that shorten reconnection. A field gateway on a 4G link can publish a reading in a few bytes of overhead, subscribe to commands such as a setpoint change, and register a last-will message so the broker announces when the gateway drops off. Topic names are hierarchical, for example:

site/hq/ahu/ahu-01/supply_air_temp
site/hq/chiller/ch-02/kw
site/hq/floor-3/zone-12/co2
site/hq/+/+/status        (filter: every asset status on site hq)

Kafka solves the back-end problem. Events are appended to partitioned, replicated topics and kept for a configured retention period; the documentation stresses that, unlike traditional messaging systems, events are not deleted after consumption. Several consumer groups can read the same topic independently and at their own pace, and a consumer can rewind to an earlier offset to reprocess data after a bug. That makes Kafka a durable buffer and distribution layer between producers and many downstream systems.

Our opinion (editorial judgement, not a statement from either project's documentation): Kafka clients and the Kafka protocol are aimed at servers and applications rather than battery-powered microcontrollers on unreliable links, and MQTT brokers are not designed to be the long-term, replayable record of every reading. That is why, in our view, the two are usually combined rather than compared.

The bridge pattern: MQTT at the edge, Kafka in the back end

A typical building or plant architecture has four layers, and it helps to keep their roles separate:

  1. Devices and gateways read BACnet, Modbus or OPC UA points, record a collection time for each (plus the source's event time where the device supplies one) and normalise them, and publish over MQTT (often with TLS on port 8883).
  2. MQTT broker (streaming at the edge) authenticates devices, routes messages to subscribers and handles retained values, last-will messages and offline sessions.
  3. Bridge into Kafka: a Kafka Connect source connector for MQTT, a broker's own Kafka integration, or a small service that subscribes to MQTT topics and produces to Kafka. It maps topic segments to fields and sets the Kafka key, for example to the asset or point ID, so that all readings for one point land in one partition and stay in order.
  4. Kafka consumers: a sink writing to the time-series database (storage and query), an alarm or rule service that raises CMMS work orders, and a job that lands history in a warehouse or lakehouse (analytics).

Kafka Connect is the documented framework for streaming data between Kafka and other systems. The Apache Kafka 4.4 Kafka Connect documentation we checked does not mention an MQTT connector, so an MQTT source connector would come from a third party or a broker vendor; we did not review any specific connector, so check the licence, support and delivery guarantees of the one you choose. The Kafka IoT data pipeline guide covers topic design, partitioning and sinks in depth, and MQTT to TimescaleDB covers the simpler path without Kafka.

Delivery guarantees and duplicates end to end

MQTT offers three quality-of-service levels per message: at most once, at least once and exactly once. The specification gives ambient sensor data as an example where QoS 0 is acceptable because the next reading follows soon after. QoS applies to each hop (device to broker, broker to subscriber), and brokers differ: the RabbitMQ MQTT plugin, for example, supports QoS 0 and 1 but not QoS 2.

Kafka guarantees at-least-once delivery by default. The idempotent producer avoids duplicates caused by producer retries, and transactions give exactly-once processing for reads and writes inside Kafka, but the documentation notes that exactly-once delivery to other destination systems generally requires cooperation from those systems. In practice an MQTT QoS 1 publish followed by an at-least-once bridge and sink can deliver the same reading twice, so make the database write idempotent with a natural key. Such a sink is at-least-once with idempotent writes; it should only be described as exactly once when offsets are stored in the same transaction as the data and a fencing check rejects writes from a consumer that has lost its partitions, as set out in Kafka consumer idempotency for sensor streams:

-- PostgreSQL: run on PostgreSQL 18.6 (PGlite)
CREATE TABLE sensor_reading (
  device_id text NOT NULL,
  point     text NOT NULL,
  ts        timestamptz NOT NULL,
  value     double precision NOT NULL,
  PRIMARY KEY (device_id, point, ts)
);

-- the same reading delivered twice by the bridge
INSERT INTO sensor_reading VALUES ('ahu-01', 'supply_air_temp', '2026-10-27 09:00:00+00', 13.4)
ON CONFLICT (device_id, point, ts) DO NOTHING;
INSERT INTO sensor_reading VALUES ('ahu-01', 'supply_air_temp', '2026-10-27 09:00:00+00', 13.4)
ON CONFLICT (device_id, point, ts) DO NOTHING;

SELECT count(*) AS stored_rows FROM sensor_reading;
-- stored_rows = 1

Without ON CONFLICT, the second insert fails with the 23505 duplicate key error. For consumer-side patterns such as offset handling and deduplication tables, see Kafka consumer idempotency for sensor streams and handling duplicate telemetry events.

Is there an MQTT database?

No. MQTT has no query language and no history. The nearest thing to storage in the protocol is the retained message: when a client publishes with the RETAIN flag, the broker replaces any existing retained message for that topic and stores the new one, so a new subscriber immediately receives the last known value. That is useful for a dashboard showing current zone CO2, but it is one value per topic, not a time series. Persistent sessions only queue messages for a disconnected subscriber until it returns.

To keep MQTT data you need a subscriber (or Kafka sink) that writes to a database: PostgreSQL or TimescaleDB, InfluxDB, QuestDB, ClickHouse or another store. Some broker products bundle such integrations, but the storage is still a database behind the broker. See how to store IoT sensor data for schema and sizing, and the time-series database selection guide to choose the store.

Retention, sizing and operations

Kafka retention is set per topic. retention.ms defaults to 7 days and can be set to -1 for no time limit; retention.bytes limits size, log compaction keeps the latest value per key, and tiered storage can move older segments to remote storage. Disk needed is roughly the write rate multiplied by retention and the replication factor (for example three copies; that figure is an illustrative assumption, and the right factor depends on your durability and availability needs). Kafka 4.x runs only in KRaft mode, in which some servers act as controllers for cluster metadata; clusters still on ZooKeeper must migrate through the 3.9 bridge release first.

An MQTT broker's sizing is driven by concurrent connections, subscriptions, message rate and the queues held for offline persistent sessions. Retained and queued messages are broker-specific; the RabbitMQ plugin, for example, keeps retained messages node-local. Plan for the slow consumer: if the database subscriber stops, an MQTT-only design has to queue or drop messages at the broker, while a Kafka design keeps them in the topic until the sink catches up. See batch vs stream ingestion and sizing storage for sensor telemetry.

Security

MQTT clients can authenticate with a user name and password or modern methods such as OAuth, and connections are encrypted with TLS (port 8883 is registered for MQTT over TLS). Topic-level authorisation is a broker feature, so define per-site and per-device permissions so a compromised gateway cannot publish to another building's command topics.

Kafka supports TLS encryption, SASL authentication and ACL-based authorisation on topics and consumer groups. Keep the two trust zones apart: devices should not connect to Kafka directly, and the bridge is the controlled crossing point between the device network and the back-end platform.

Pricing and licensing

Apache Kafka is distributed under the Apache License, Version 2.0, whose copyright grant reads in part: "each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license", subject to the licence's terms and conditions. The running cost is the cluster you run (brokers, controllers, disks, network) and the people to operate it. Kafka's documentation notes that fully managed services are offered by a variety of vendors; they price by throughput, partitions, storage or cluster size in different ways, so compare them on your own write rate and retention. We did not check individual vendors' price lists for this page.

MQTT is an OASIS standard; the protocol itself is not a product you license, but every broker and client library has its own licence. Eclipse Mosquitto is an open source project, and RabbitMQ (which ships the MQTT plugin) states that it is "Free under the Mozilla Public License 2.0"; read each project's licence file for the terms. Commercial and cloud IoT brokers set their own pricing models (for example by connected devices, connection time or message volume); we did not check individual price lists for this page. As with Kafka, estimate from device count, publish interval and message size.

Licence descriptions here are factual summaries with quotes from the official licence texts and vendor pages; they are not legal advice. Read the licence and take advice for your situation.

Pricing checked on the vendors' official pages on 27 October 2026. Prices change; confirm before buying.

Where each one leads

Apache Kafka strengths

  • Durable, replicated, partitioned log that keeps events for a configured retention period
  • Many independent consumer groups can read the same stream at their own pace
  • Consumers can rewind to an earlier offset and reprocess after a bug or outage
  • Kafka Connect and Kafka Streams for integration and stream processing
  • Buffers data while downstream databases are slow or offline

MQTT strengths

  • Designed for constrained devices and low-bandwidth, high-latency or unreliable networks
  • Three QoS levels chosen per message, from fire-and-forget to exactly once (QoS 2 applies per hop, where the broker supports it)
  • Retained messages give new subscribers the last known value at once
  • Last Will and Testament and keep-alive show when a device or gateway drops off
  • Open standard with many brokers and client libraries, including for microcontrollers

Limitations

Apache Kafka limitations

  • Not designed as a device protocol; clients are heavier than MQTT clients
  • A cluster to size and operate (brokers, KRaft controllers, disks, partitions)
  • Exactly-once results in an external database need sink-side safeguards: offsets stored with the data and a fencing check against outdated consumers; otherwise a sink is at-least-once with idempotent writes
  • In our editorial view, often more than a single site with one consumer needs

MQTT limitations

  • No history or replay in the protocol; storage requires a database subscriber
  • QoS applies per hop, and broker support for QoS 2 and other features varies
  • Fan-out to many back-end systems with different speeds is limited by broker queues
  • Not a database and has no query language

When to choose each

Choose Apache Kafka if

  • Several back-end systems need the same readings: time-series database, alarm service, data lake
  • You need to replay history after a bug, a schema change or a new consumer
  • Ingestion must continue while a database is down or being upgraded
  • Events come from back-end services and databases as well as from devices

Choose MQTT if

  • Devices or gateways publish over cellular, Wi-Fi or other constrained links
  • Commands and setpoints must flow back to devices
  • Dashboards need the last known value of each point immediately
  • A single site where one subscriber writes readings to the database is enough

When neither is right

Final recommendation

Bottom line

In our assessment (an editorial judgement based on the documented roles above), Kafka versus MQTT is usually the wrong question. MQTT is the protocol devices and gateways should speak: small, tolerant of poor networks, with QoS levels, retained values and last-will messages. Kafka is the back-end event log that stores the stream durably and feeds many consumers, with replay. Join them with a bridge that keys events by asset or point, and make every database sink idempotent. For a single site with one database and modest volumes, an MQTT broker plus a reliable subscriber is often enough; add Kafka when fan-out, replay or buffering becomes a real requirement. In every case the readings are stored and queried in a database, not in either messaging layer.

Frequently asked questions

Can Kafka replace MQTT?

Not at the device edge. Kafka is designed for servers and applications and stores events in partitioned topics; MQTT is designed for constrained devices on unreliable networks, with features such as last-will messages and retained values. Most IoT systems use MQTT from devices to a broker and Kafka behind it.

Can MQTT replace Kafka?

For small systems, yes: an MQTT broker and one subscriber that writes to a database may be all you need. MQTT does not keep history or support replay, so when several systems need the stream, or ingestion must survive a database outage, Kafka adds a durable buffer.

Is MQTT a database?

No. MQTT is a messaging protocol. A broker can hold one retained message per topic and queue messages for offline sessions, but it does not store history or answer queries. Store readings in a database through a subscriber or a Kafka sink.

How do I get MQTT data into Kafka?

Use a bridge: a Kafka Connect MQTT source connector, a broker's built-in Kafka integration, or a small service that subscribes to MQTT topics and produces to Kafka. Set the Kafka key to the asset or point ID to keep each point's readings in order, and make downstream sinks idempotent because the path is at least once.

Does MQTT guarantee exactly-once delivery?

MQTT defines QoS 2, exactly once, between a client and the broker, but it applies per hop and not every broker supports it (the RabbitMQ MQTT plugin supports QoS 0 and 1 only). End to end, design for duplicates and deduplicate in the database.

Sources

Checked October 2026.

How we research comparisons: our editorial method.

More comparisons

Browse all SQL comparisons or the tools directory.