On this page
Short answer
Use Mosquitto (or another MQTT broker) where devices connect: sensors, gateways and vehicles on unreliable networks that need a small client, keepalives, a last will, retained messages and QoS 0, 1 or 2. Use Kafka behind it, where the data has to be stored, replayed, processed in streams and fed to many independent systems. They are not substitutes: Kafka does not speak MQTT, and Mosquitto keeps no history. Most IoT platforms run both, with Mosquitto at the edge and a Kafka Connect MQTT connector moving the data into Kafka topics.
Eclipse Mosquitto and Apache Kafka on the same criteria
| Eclipse Mosquitto | Apache Kafka | |
|---|---|---|
| What it is | MQTT broker: routes messages from publishers to subscribers by topic | Distributed log: stores records in partitioned, replicated topics |
| Protocol | MQTT 5.0, 3.1.1 and 3.1, over TCP, TLS or WebSockets | Kafka's own binary protocol; no MQTT support |
| Delivery | QoS 0 at most once, QoS 1 at least once, QoS 2 exactly once, each per hop | At least once by default; idempotent producer and transactions for exactly-once between topics |
| Storage | In memory; optional persistence of sessions, queued and retained messages | Every record on disk until retention removes it, seven days by default |
| Replay | No; a retained message keeps only the last value per topic | Yes, from any retained offset, by any consumer group |
| Scaling | One broker; bridges link brokers. No clustering in the open-source edition | Cluster of brokers with replicated partitions and KRaft controllers |
| Device features | Keepalive, last will, retained messages, session expiry, shared subscriptions | None for devices; consumer groups, share groups, Connect and Streams for services |
| Default size limit | max_packet_size 2,000,000 bytes since 2.1 (MQTT allows up to 256 MB) | message.max.bytes 1,048,588 bytes (about 1 MB) |
| License and release | EPL-2.0 or EDL-1.0, Eclipse Foundation; 2.1.2 (9 February 2026) | Apache 2.0, Apache Software Foundation; 4.3.1 (25 June 2026) |
Different jobs: device connectivity versus an event log
Mosquitto implements MQTT, a publish-subscribe protocol designed for constrained devices and unreliable links. A client connects, publishes to a topic such as plant1/line3/temp, and the broker forwards the message to every client whose subscription matches, including wildcards like plant1/+/temp. MQTT carries the features devices need: a keepalive so the broker notices dead connections, a last will message the broker publishes when a client drops without disconnecting, retained messages so a new subscriber immediately gets the last value on a topic, and persistent sessions that hold QoS 1 and 2 messages for a client while it is offline. Mosquitto is small enough for a single-board computer as well as a server.
Kafka is built for services, not devices. Producers append records to topics split into partitions; consumers pull, track their own offsets and can go back to any retained position. Reading does not delete anything, so a fraud model, a data lake loader and a dashboard can each consume the same telemetry independently, and a new one can start from last month. That is the job Mosquitto does not attempt.
Delivery guarantees: MQTT QoS is per hop
MQTT defines three quality-of-service levels: 0 (at most once), 1 (at least once, so duplicates are possible) and 2 (exactly once, using a four-step handshake). Each applies to one hop, publisher to broker or broker to subscriber, and the MQTT 5.0 specification has the broker deliver at the lower of the publish QoS and the QoS granted to the subscription. A device publishing at QoS 2 to a subscriber at QoS 0 gets QoS 0 on the second hop. QoS 2 does not make delivery into Kafka exactly-once either: the connector reading from the broker is one more hop with its own guarantees.
Kafka producers default to acks=all with idempotence enabled, which removes duplicates from producer retries, and transactions give exactly-once processing between Kafka topics. In practice an MQTT-to-Kafka pipeline is at-least-once end to end, so give each reading an ID or a device timestamp and make consumers idempotent.
Persistence, retention and replay
Mosquitto keeps its state in memory. With persistence true (off by default) it writes connection, subscription and message data to mosquitto.db on shutdown and every autosave_interval, 1,800 seconds by default, so a crash loses what changed since the last save. Mosquitto 2.1 added a persist-sqlite plugin, and the documentation now recommends plugin-based persistence over the built-in file. Queues for offline clients are bounded: once a client has max_queued_messages waiting, 1,000 by default, further messages for it are dropped. None of this is history; a message delivered is gone.
Kafka writes every record to disk on each replica and keeps it for the topic's retention, seven days by default (log.retention.hours=168), by size, forever, or as the latest value per key with log compaction. That is why telemetry that must be reprocessed, audited or used to train models belongs in Kafka, or in storage fed from it, rather than in the MQTT broker.
Scaling and high availability
An open-source Mosquitto broker is a single process. To spread load or link sites you run several and connect them with bridges: a bridge is a client connection from one broker to another, configured with connection, address and one or more topic lines giving the pattern, the direction (in, out or both), the QoS and optional prefixes for remapping. Two defaults catch people out: a bridge topic's QoS defaults to 0, and bridge_protocol_version defaults to MQTT 3.1.1, with mqttv50 available. Clustering and high availability are not in the open-source edition; the Mosquitto site lists them for Cedalo's commercial Pro Edition.
Kafka scales a topic by adding partitions across brokers and replicates each partition, usually three times, so a broker can fail without losing acknowledged data. Since Kafka 4.0, released on 18 March 2025, KRaft controllers manage metadata and ZooKeeper is gone. Our Kafka architecture guide covers how that fits together.
The common pattern: MQTT at the edge, Kafka behind it
Most IoT platforms combine the two. Devices publish to Mosquitto, at each site or centrally; a Kafka Connect MQTT source connector subscribes to the broker and writes the messages to Kafka topics; stream processors, databases and analytics read from Kafka. Commands travel the other way through an MQTT sink connector. Two connector families are common: Confluent's MQTT source and sink connectors, which run for a 30-day trial and then need a Confluent enterprise subscription, and the Lenses Stream Reactor MQTT source and sink, which are Apache 2.0.
Points that decide whether the bridge loses data:
- Subscribe the connector at QoS 1 with a persistent session, so the broker queues messages while the connector restarts, and size
max_queued_messagesfor the longest restart you expect. - Map many MQTT topics to a few Kafka topics, and put the device ID in the Kafka record key so each device's readings stay in order in one partition. A Kafka topic per device does not scale.
- Expect duplicates at QoS 1 and deduplicate downstream.
- If edge brokers bridge to a central broker first, set the bridge topic QoS explicitly instead of leaving it at 0.
RabbitMQ as the MQTT broker
If you want MQTT and service messaging in one broker, RabbitMQ is the usual alternative to Mosquitto. Its MQTT plugin ships with the core distribution and supports MQTT 3.1, 3.1.1 and 5.0. Messages from MQTT clients are routed through the amq.topic exchange, so AMQP 0.9.1 and AMQP 1.0 consumers can read them from bound queues, and MQTT publishers can also write to RabbitMQ streams. Durable subscriptions can use quorum queues (mqtt.durable_queue_type = quorum), and RabbitMQ clusters natively, which the open-source Mosquitto broker does not. Kafka still sits behind it when the data needs long retention and many independent consumers. Our RabbitMQ consulting team designs these deployments, and RabbitMQ vs Kafka compares the two brokers directly.
When to choose which
- Are the clients devices on constrained hardware or unreliable networks? An MQTT broker such as Mosquitto.
- Must the data be stored, replayed or read by many independent systems? Kafka.
- Do you need high availability for the MQTT layer without a commercial license? RabbitMQ's MQTT plugin, or another clustered MQTT broker.
- Do you need both? Mosquitto or RabbitMQ at the edge, a Kafka Connect MQTT connector, and Kafka as the system of record.
Frequently asked questions
Is Mosquitto the same as Kafka?
No. Mosquitto is an MQTT broker that routes messages between connected clients and keeps no history. Kafka is a distributed log that stores records on disk and lets consumers replay them. They speak different protocols, and Kafka clients cannot connect to Mosquitto or the reverse.
Can Kafka replace an MQTT broker?
Not directly. Kafka has no MQTT support, so devices would need Kafka client libraries and direct connections to the brokers, and they would lose MQTT features such as last will, retained messages and per-hop QoS. Keep an MQTT broker at the edge and bridge into Kafka.
How do I get MQTT data from Mosquitto into Kafka?
Run a Kafka Connect MQTT source connector that subscribes to Mosquitto and writes to Kafka topics. Confluent's connector needs a Confluent subscription after a 30-day trial; the Lenses Stream Reactor MQTT connector is Apache 2.0. Subscribe at QoS 1 with a persistent session and key records by device ID.
Does Mosquitto support clustering?
The open-source broker does not. You can link brokers with bridges, which forward selected topics, but there is no shared state or automatic failover. The Mosquitto site lists high availability as a feature of Cedalo's commercial Pro Edition.
Does Mosquitto support MQTT 5?
Yes. Mosquitto implements MQTT 5.0, 3.1.1 and 3.1. The current release is 2.1.2, from 9 February 2026; 2.1.0 lowered the default max_packet_size to 2,000,000 bytes, so larger payloads need that option raised.
Related
Where this gets done
The work behind this page, run by the same engineers who wrote it.
- 24/7 Kafka supportSelf-managed, MSK or Confluent Platform
- Managed Kafka servicesWe run the clusters, on your infrastructure
- Debezium CDC supportChange data capture from Oracle, SQL Server and PostgreSQL
- Kafka consultingPartition strategy, sizing, security and migration
- RabbitMQ supportIf the estate runs both brokers
- Kubernetes and container servicesKafka on Kubernetes, operated with your team
- Enterprise MQ supportOne contract across Kafka, RabbitMQ and IBM MQ
- Enterprise support plansSLA tiers and what each covers
- Enterprise MQ consultingMulti-broker architecture and migration
Other Kafka guides, comparisons and research
- GuideThe Kafka Operations GuideRead the guide
- GuideBuying Kafka Support: The GuideRead the guide
- GuideThe Kafka Monitoring and Alerting GuideRead the guide
- GuideThe Kafka Migration GuideRead the guide
- GuideKafka for AI Agents Without Confluent CloudRead the guide
- ComparisonKafka vs Kinesis ComparedSee the comparison
- ComparisonManaged Kafka Options ComparedSee the comparison
Recent Kafka articles
- Kafka Health Check: What a Real Assessment CoversOct 2026
- What Is Kafka Used For? 8 Common Use CasesOct 2026
- Kafka Event-Driven Architecture: Patterns and PitfallsOct 2026
- How Much Does Kafka Enterprise Support Cost?Oct 2026
- Kafka Disaster Recovery: Architectures, RPO/RTO, TestingOct 2026
- Apache Kafka End of Life: Supported Versions in 2026Oct 2026
Need this done on your Kafka estate?
Named senior Kafka engineers, 24/7, with a 15-minute emergency SLA — self-managed, MSK or Confluent Platform.