• New
📢 Zilla is now a complete MQTT broker on Kafka: every line of the spec, benchmarked at 100K clients
Learn more →

Engineering

November 30, 2026

Every Line of the Spec: How Zilla Became an MQTT Broker on Kafka

Zilla speaks MQTT 3.1.1 and 5 natively on Kafka, verified against all 390 normative statements in the two specifications.

Authors
John Fallows
Aklivity Engineering

Your MQTT bridge to Kafka may be quietly bending the protocol. Not on the easy path, where a device connects, publishes at QoS 0 and goes away, but at the edges every fleet reaches eventually. A device reconnects after an hour offline and expects its session to be waiting. A dashboard subscribes and wants the retained value for each topic exactly once. A will message should fire when the network drops, but not when the device says a clean goodbye.

Most MQTT-to-Kafka integrations handle this one of two ways. Some put a separate MQTT broker in front of Kafka and a connector behind it, so you run, secure and scale two systems that disagree about where state lives. Others implement the parts of MQTT that map easily onto Kafka and leave the rest out. Either way, your devices find out which parts are missing at runtime, usually in production.

We took a different path with Zilla: speak MQTT natively, keep your data in Kafka, and run no separate broker at all. In this post we walk through how that support grew, from MQTT 5, to MQTT 3.1.1, to shared subscriptions built on Kafka's new share groups, to session management rebuilt on Zilla's stores, and the engine work that lets Zilla absorb a fleet-wide reconnect storm. Most of all, we want to show you how we measure conformance: all 390 numbered normative statements in the two specifications, checked one by one against our code.

Where we started: MQTT 5

We started with MQTT 5, because it is the version that says the most about state. Session expiry, message expiry, will delay, user properties and detailed reason codes all describe things a broker must remember and report. If our Kafka mapping could hold MQTT 5's state faithfully, MQTT 3.1.1 would be a subset of it rather than a retrofit.

If you have read How Zilla Works, the shape will look familiar. An MQTT broker in Zilla is a pipeline of bindings: an mqtt server that speaks the wire protocol, an mqtt-kafka proxy that maps MQTT streams onto Kafka streams, and the Kafka cache client that talks to your cluster.

bindings:
  north_mqtt_server:
    type: mqtt
    kind: server
    exit: north_mqtt_kafka_mapping

  north_mqtt_kafka_mapping:
    type: mqtt-kafka
    kind: proxy
    options:
      topics:
        sessions: mqtt-sessions
        messages: mqtt-messages
        retained: mqtt-retained
    exit: north_kafka_cache_client

In that first design, the whole broker lived in those three Kafka topics. There was no broker-side disk, no replication protocol of our own, and no state that existed only in one Zilla instance's memory:

MQTT conceptWhere it lived in Kafka
A published messageA record on the messages topic, keyed by the MQTT topic name, with MQTT properties carried as Kafka headers
A retained messageA record on the compacted retained topic, keyed by topic name; a zero-byte retained publish writes a tombstone
Session state (subscriptions, will message)A compacted record per client id on the sessions topic
Delivery progress for QoS 1 and 2Offsets committed per client session

Because the MQTT topic is the Kafka key, every message for one topic lands on one partition, in order. Because the session lived in Kafka, a device that reconnected to a different Zilla instance after a scale-in found its subscriptions and its will exactly where it left them. And because the messages are ordinary Kafka records, your stream processors, connectors and analytics read device data directly, with no export step in between. Routes can also send particular topic patterns to their own Kafka topics, so device telemetry and device commands don't have to share one.

That design proved the model. As deployments grew, it also showed us that not all broker state belongs in Kafka, which we come back to below.

MQTT 3.1.1, for the devices you already have

MQTT 5 is where new designs start, but MQTT 3.1.1 is what most fleets actually run. Firmware in the field is expensive to change, and plenty of devices will speak 3.1.1 for the rest of their service life. So we added MQTT 3.1.1 to the same mqtt server binding, on the same port, negotiated per connection from the protocol level in CONNECT. Both versions shipped in Zilla 1.0.

The important design decision was where the version differences stop. The mqtt server absorbs them, and everything behind it, including the Kafka mapping, sees one kind of MQTT stream. A 3.1.1 device and a 5 device can publish to and subscribe on the same topics and share the same session state, and neither knows the other exists.

Absorbing the differences faithfully is more subtle than it sounds, because 3.1.1 expresses some of the same ideas in a different shape:

ConceptMQTT 3.1.1MQTT 5What Zilla must do
Keeping a sessionClean Session = 0 keeps it, with no expiryClean Start plus a Session Expiry IntervalTreat Clean Session = 0 as an interval of 0xFFFFFFFF, which means the session never expires
Reporting a failed connectReturn codes 0 to 5 onlyOver 20 reason codesNever send a 3.1.1 client a code it cannot parse
Retained replayRETAIN = 1 on every replayed messageControlled by Retain As PublishedSet the flag on replay whatever the client's version
MetadataNoneUser properties, content type, response topicCarry it when present, and never require it

A mistake in any of these rows is easy to miss in testing and costly in the field. For example, a 3.1.1 device that asked to keep its session, but gets a fresh one after a reconnect, silently loses every QoS 1 message published while it was away.

Verified against every line of the spec

Every MQTT broker has a test suite, and ours is a large one. But a test suite only covers the cases its authors chose to write, while the specification is the real contract between a broker and your devices, including in the cases nobody thought to test. So we verify Zilla against the specifications themselves.

Both OASIS specifications number their normative statements, the MUSTs and MUST NOTs, with identifiers like [MQTT-3.1.2-2]. MQTT 3.1.1 has 139 of them and MQTT 5 has 251. We verify Zilla against all 390, end to end through the real mqtt-kafka pipeline rather than against mocks of the components on either side. Every behavior change starts with a test that fails first, so the suite grows with the spec, not with our assumptions.

The edges are where MQTT implementations most often differ. Here is a sample of how Zilla behaves there:

AreaWhat the spec requiresHow Zilla behaves
RetainedRetain Handling 1 sends retained messages only for a new subscription (section 3.8.3.1)Replays on a new subscription, and stays silent on a repeat
RetainedA replayed retained message carries RETAIN = 1 (section 3.3.1.3)Sets RETAIN on every replay, for 3.1.1 and 5 clients alike
RetainedA zero-byte retained publish removes the retained message (section 3.3.1.3)Writes a Kafka tombstone, so compaction removes it for good
Sessions3.1.1 Clean Session = 0 keeps the session (section 3.1.2.4)Persists the session, with no expiry
SessionsWill Delay Interval up to 4,294,967,295 seconds (section 3.1.3.2.2)Honors the full unsigned range, across instances
QoS 2A PUBREC with a failure code ends the flow without PUBREL (section 4.3.3)Ends the flow cleanly and frees the packet id
QoS 2An unknown PUBREL is answered with PUBCOMP 0x92 (section 3.7.2.1)Answers with 0x92, so a client retransmitting after a lost PUBCOMP recovers
OrderingAcknowledgments follow the order PUBLISH packets arrive (section 4.6)Acks pipelined publishes in receive order, across topics
TopicsTopic names must not contain wildcards (section 3.3.2.1)Rejects a PUBLISH to a topic containing + or #
TopicsWildcards don't match topics starting with $ (section 4.7.2)Keeps $ topics out of wildcard subscriptions
TopicsStrings are well-formed UTF-8 with no U+0000 (section 1.5.4)Validates every string field, not only text payloads
SubscribeA repeat SUBSCRIBE replaces the existing subscription (section 3.8.4)Replaces it, including its QoS and Subscription Identifier
UnsubscribeOne UNSUBACK reason code per filter, in request order (section 3.11.3)Returns exactly one code per filter, in order
Flow controlThe client's Maximum Packet Size and Receive Maximum are respected (sections 3.1.2.11, 4.9)Enforces both per connection, holding messages until a slot frees
ExpiryMessage Expiry Interval counts down in seconds (section 3.3.2.3.3)Forwards the remaining interval and drops a message only once it has expired

Topic matching is a good illustration of how much hides in a few lines of the spec. These are the rules from section 4.7 that Zilla applies to every subscription:

  
filter  sport/#      matches  sport           (parent level matches #)
filter  a/+          matches  a/              (a trailing empty level is still a level)
filter  a            does not match  a/
filter  +/monitor    does not match  $SYS/monitor   ($ topics need an explicit first level)
  

Each rule is a small detail in the code, but getting one wrong means a subscriber silently misses messages, or receives ones it never asked for.

Getting the best out of Kafka

A traditional MQTT broker has to build its own durability, replication and replay. Zilla doesn't need to, because Kafka already provides all three, and has been hardened for them in production for years. Your MQTT data maps onto the Kafka capability that already does that job best, so your MQTT traffic inherits Kafka's strengths directly:

Kafka capabilityHow Zilla uses itWhat it means for you
Log compactionEach retained message is one compacted record per topic, and each will message one compacted record per client idRetained values and wills are durable and replicated alongside the rest of your data
RetentionThe messages topic holds the history every session reads fromYou choose how long a device can be offline and still receive everything, with one setting you already know
Replication and acknowledgmentA publisher's PUBACK is sent once Kafka has the messageAn acknowledged message is as durable as any Kafka record, with the same guarantees your other producers rely on
ReplayAfter a reconnect, unacknowledged messages are re-read from the logAt-least-once delivery holds across reconnects and across Zilla instances

Kafka provides the durability, replication and scale it is known for. On top of it, Zilla provides the full MQTT protocol, verified against every line of the spec.

Shared subscriptions on Kafka share groups

Shared subscriptions let a group of subscribers split the work of a single subscription between them. A subscription to $share/workers/orders/# asks the broker to spread messages across the group's members, each message to one member, with redelivery if a member fails before acknowledging it. That is a work queue, and until recently Kafka had no work queue to map it onto.

Many bridges build one on consumer groups instead. But consumer groups assign whole partitions to members, so a shared subscription built on them either caps its parallelism at the partition count or needs a second queue on the side to hand out individual messages. Both change the semantics your subscribers rely on: when to scale, what happens on failure, and which messages can be redelivered.

Kafka's share groups (KIP-932) changed that. A share group hands out individual records rather than partitions, each acquired under a lock with a delivery count, and acknowledged, released or rejected one at a time through the new ShareFetch and ShareAcknowledge APIs. That maps onto MQTT almost one to one:

MQTT shared subscriptionKafka share group
Share name in $share/{name}/{filter}Share group
Message delivered to one member of the groupRecord acquired by one consumer
PUBACK from the memberRecord acknowledged
Member disconnects before acknowledgingAcquisition released; the record is redelivered
DUP = 1 on a redelivered messageDelivery count above one
Adding members to scale outMore consumers in the share group, beyond the partition count

Shared subscriptions shipped in Zilla 2.8 and require Kafka 4.1 or later with share groups enabled; share groups are a preview in Kafka 4.1 and production-ready from 4.2. They went through the same conformance discipline as everything else, with their own positive and negative $share scenarios run through the real pipeline. Because we waited for share groups, the semantics your subscribers see are Kafka's own, rather than an approximation of them.

A home for session state: Zilla stores

When we first built the mqtt-kafka mapping, Zilla had no concept of a store. Kafka was the only durable, shared place we had, so session state went into a compacted sessions topic alongside everything else. It worked, and it proved the model. But session state is not like device data.

Device data is a stream: appended once, kept in order, and read by many consumers, which is exactly what Kafka is built for. Session state is a small record per client that is read and rewritten on every connect, subscribe and unsubscribe. In a reconnect storm, that means hundreds of thousands of lookups and updates at once, each one on the critical path to a device's CONNACK. That is a job for a key-value store.

Zilla's stores gave session state that home. A store is declared once in zilla.yaml, alongside bindings, guards, vaults and catalogs, and used by any binding that needs it. The memory store holds state in process for a single instance or for testing, and the redis and hazelcast stores, available in Zilla Plus, keep state persistent and shared across every Zilla instance.

Zilla also provides sys:memory as a built-in system store, so there is nothing to declare: the mqtt server binding simply refers to it by name.

bindings:
  north_mqtt_server:
    type: mqtt
    kind: server
    options:
      store: sys:memory
    exit: north_mqtt_kafka_mapping

We have now moved MQTT session management fully into the store. Each kind of broker state lives where it performs best:

Broker stateWhere it livesWhy
Published messagesKafka messages topicOrdered, durable, and read directly by your stream processors
Retained messagesCompacted Kafka retained topicThe last value per topic, replayed to each new subscription
Will messagesCompacted Kafka sessions topicA will must outlive the connection that registered it, and is published to Kafka when it fires
Sessions: subscriptions, delivery state, expiry and takeoverZilla storeRead and updated on every connect, at memory speed, by any instance

The sessions topic now carries only will messages. Everything a reconnecting device needs before its CONNACK is a key lookup in the store, and that is what makes the performance in the next section possible.

Conformance at scale

Reconnect storms are where an MQTT broker is tested hardest. The hardest moment in an IoT deployment is rarely steady state. It's the minute after a network outage or a load balancer restart, when every device reconnects at once, each one resuming its session, re-subscribing and draining what it missed.

So alongside the conformance work we benchmarked MQTT at fleet scale, and tuned the engine for exactly that moment. With sessions in the store, three changes to the engine came out of it.

Connection ramping. A reconnecting device's session is now a key lookup in the store rather than a read from Kafka, so the connect path never waits on the log, and the accept path itself is tuned to take on new connections in bursts. For a fleet, that is the difference between a reconnect storm that clears in seconds and one that cascades into timeouts and more reconnects.

Automatic connection balancing. Each Zilla engine worker owns one CPU core, and MQTT connections live for days. If the operating system hands a burst of new connections unevenly to workers, that imbalance used to stick for the life of those connections. Every worker now listens for new connections, and Zilla rebalances accepted connections across workers automatically, so every core carries its share of the fleet and no one worker becomes the bottleneck.

Lock-free parallel cache writers. Every MQTT message passes through Zilla's Kafka cache on its way to and from your cluster. Workers can now write to the cache in parallel without taking locks, so ingest scales with cores instead of serializing behind one writer.

Together, the store and these engine changes give Zilla best-in-class MQTT performance on Kafka. We'll share the numbers in a dedicated post on our MQTT benchmarks. In the meantime, the scenarios are in aklivity/mqtt-benchmark, so you can run them against your own hardware and your own Kafka cluster.

What it means for the people using it

Conformance is only interesting because of what it changes for people, so let's be concrete.

For device and firmware engineers, the broker behaves the way the spec says it will, in both versions. Persistent sessions survive reconnects and failover between Zilla instances. Will messages fire when they should and not when they shouldn't. Retained values arrive once per new subscription, flagged as retained. You can move a fleet from 3.1.1 to 5 one device at a time, against the same topics.

For platform teams, there is one system to run instead of two. There is no separate broker cluster to size, patch and replicate, and no connector between it and Kafka to monitor. Zilla instances hold no state of their own, with sessions in a shared store and data in Kafka, so you scale them like any other service, and a scale-in moves connections without ending sessions.

For data and streaming teams, device data is ordinary Kafka data the moment it is published, keyed by MQTT topic and in order per topic. Your stream processors read it directly, and commands you write to Kafka reach devices as MQTT messages. Shared subscriptions let backend services consume device traffic as a work queue, with Kafka's own share-group semantics.

For security and compliance teams, conformance is verified against the specification rather than assumed, and the few behaviors shaped by Kafka are documented with their reasons. Connections can be authorized with JWT, with publish and subscribe privileges enforced per topic, and every message can be validated against a schema before it reaches Kafka.

Where we go next

Zilla already authorizes every MQTT connection through its guards, such as JWT with publish and subscribe privileges enforced per topic, so the same identity providers protect your MQTT, HTTP and Kafka traffic alike. Next we're extending that guard model to MQTT 5's enhanced authentication, the multi-step challenge and response exchange of the AUTH packet.

A real MQTT broker, built on Kafka

When we started, the question was whether you could build a real MQTT broker on Kafka, or only a bridge that speaks enough MQTT to get by. Zilla answers it. It speaks MQTT 3.1.1 and 5 as the specifications define them, keeps your data in Kafka, and runs on the same streaming engine we have spent years tuning for protocol traffic at scale.

We think your devices should not have to know that their broker is Kafka. See it for yourself: the MQTT to Kafka guide runs a complete MQTT broker on Kafka on your own machine with a single docker compose up. Point your existing MQTT 3.1.1 or 5 clients at it, then join our community and tell us what you're connecting to Kafka next!

Related Resources

Engineering

Benchmarks

High-Performance MQTT-Kafka Integration with Zilla: Aklivity Zilla Benchmark Series (Part 5)

Engineering

Benchmarks

Sub-Millisecond Median Overhead for the Zilla LLM Gateway: Aklivity Zilla Benchmark Series (Part 4)

Engineering

What Is a Kafka Gateway and When Is One Needed?

Ready to Get Started?

Get started on your own or request a demo with one of our data management experts.

Explore pricing

Straightforward, usage-based pricing with no per-connection surprises — start free and scale when you are ready.

Pricing details

Join the Community

Trade notes with the engineers running Zilla in production, and get help from the team in Slack or Discord.