MQTT
A compact publish-subscribe protocol built for intermittent networks, constrained devices, hierarchical topics, and broker-pushed delivery.
Best for device-to-cloud and command-and-control messaging.
Protocol comparison
Use MQTT alone for live device connectivity and commands without a replayable backend log. Use Kafka alone for trusted backend producers and durable event processing. Use both when constrained devices need MQTT sessions at the edge and multiple backend consumers need retained, replayable events behind a controlled bridge.
The protocols solve different boundaries. MQTT optimizes the device connection; Kafka optimizes the durable processing backbone.
MQTT
A compact publish-subscribe protocol built for intermittent networks, constrained devices, hierarchical topics, and broker-pushed delivery.
Best for device-to-cloud and command-and-control messaging.
Apache Kafka
A distributed event log built for durable retention, partitioned throughput, consumer-controlled offsets, replay, and stream processing.
Best for service-to-service event pipelines, analytics, and replay.
| Capability | MQTT | Kafka |
|---|---|---|
| Device connection lifecycle | Native fit: lightweight clients, keepalive, sessions, reconnect, and Last Will | Backend clients assume stable connectivity and Kafka protocol support |
| Core model | Brokered publish-subscribe with hierarchical topics | Partitioned append-only log with consumer offsets |
| Typical clients | Sensors, embedded devices, gateways, mobile clients | Backend services, connectors, stream processors |
| Delivery | Broker pushes matching messages; QoS 0, 1, or 2 | Consumers pull and commit offsets per consumer group |
| Command downlink | Broker-pushed command topics with per-device authorization, expiry, and acknowledgments | Requires an application gateway to authorize and translate events into device commands |
| Retention and replay | Retained latest value and session queues; not a general event archive | Time- or size-based durable retention with offset replay |
| Ordering and partitioning | Order is scoped to a client connection and Topic delivery; no consumer partition model | A record key selects a partition; order is guaranteed only within that partition |
| Independent processing consumers | Subscriptions fan out live delivery; shared subscriptions divide work without durable offsets | Consumer groups keep independent offsets and scale processing across partitions |
| Routing | Hierarchical topic filters with + and # wildcards | Flat topics and partitions; routing belongs in producers or processors |
| Network assumptions | Designed for low bandwidth, high latency, and reconnecting clients | Designed for stable data-center or cloud service connectivity |
A single system can use both without duplicating their responsibilities.
Keep protocol responsibilities explicit so replay, backpressure, and authorization remain understandable.
Unique identity; versioned telemetry
TLS, sessions, Topic ACLs, command delivery
Schema, envelope, retry, DLQ
Partitioned retention and replay
Independent processing and offsets
The repository example starts loopback-only Mosquitto and Redpanda containers, validates a synthetic telemetry schema, keys Kafka records by deviceId, retries bounded failures, and routes invalid records to a DLQ. It is a learning fixture—not a production connector: the anonymous local broker has no device identity, and the bridge has no durable spool between MQTT acknowledgment and Kafka acknowledgment.
docker compose -f public/examples/mqtt-kafka-bridge/compose.yaml up -d
pnpm mqtt:kafka-bridge
# In a second shell, publish a synthetic event
docker compose -f public/examples/mqtt-kafka-bridge/compose.yaml exec mosquitto \
mosquitto_pub -h 127.0.0.1 -t lab/device-042/telemetry -q 1 \
-m '{"eventId":"evt-001","recordedAt":"2026-01-01T00:00:00Z","value":21.4}'Kafka is not a drop-in device broker. It does not provide MQTT sessions, QoS flows, retained messages, hierarchical topic filters, or the same constrained-client footprint.
MQTT can queue session messages and retain a latest value, but it is not designed as a long-lived replayable event log for many independent backend consumers.
Run it at a controlled ingestion boundary where credentials, schemas, retry behavior, partition keys, and dead-letter handling can be operated and observed.
Continue from architecture boundaries into MQTT implementation, security, operating model, fleet scaling, and plan selection.
Understand browser transport, MQTT responsibility boundaries, and reconnect behavior.
Follow a message from client connection through Topic delivery.
Protect device identity, transport, and topic permissions.
Assign ownership for broker upgrades, availability, and security operations.
Plan connection, subscription, reconnect, and regional capacity before adding downstream pipelines.
Compare managed MQTT broker plans for the device connection layer.