Skip to content
← Engineering notes

Embedded firmware and MCU choice

MQTT topic and payload design that still works at a thousand devices

14 November 2026 · Shalaka engineering team

MQTT is simple enough that a prototype with ten devices works with almost any topic naming. At a thousand devices, the same naming decides whether access control, debugging and cloud rules are easy or miserable. Topics are baked into firmware in the field, so they are hard to change later.

A topic hierarchy you can filter and secure

Put the stable, wide parts first and the specific parts last:

org/<customer>/<site>/<device_id>/<channel>

with channels such as telemetry, status, event, cmd and cmd/ack. Wildcards then become useful: +/+/+/+/status is every device’s status, and a broker rule can limit a device to its own subtree.

Keep these habits:

  • Use the device ID in the topic, not in the payload only, so broker ACLs can enforce that a device publishes only as itself.
  • Never put variable data such as a temperature value in the topic.
  • No leading slash, no spaces, and no wildcard characters in names.
  • Separate commands to a device from data from a device.

Choosing QoS

QoS 0 is fire and forget. QoS 1 delivers at least once, so duplicates are possible. QoS 2 is exactly once, at the cost of a four-part handshake. For telemetry, QoS 0 or 1 is usually right, and a timestamp or sequence number in the payload lets the cloud discard duplicates. Commands that change state, such as “open valve”, should be QoS 1 and idempotent, so receiving them twice does no harm. QoS 2 is rarely worth its cost on a constrained device or a metered link.

Retained messages and last will

A retained message is the last value the broker keeps for a topic, handed to any new subscriber. Use it for state, such as status and current configuration, not for a stream of readings.

Pair it with a last will. On connect, the device registers a will message, “offline” on its status topic, retained. It then publishes “online”, retained, once connected. If the device drops without a clean disconnect, the broker publishes the will after the keep-alive expires, typically one and a half times the keep-alive interval. A dashboard can then show which devices are down without polling.

Version the payload

Include a schema version field in every payload, such as "v":2. Firmware in the field will not all update at once, so the cloud has to read both v1 and v2 for months. Add fields, do not change the meaning or unit of existing ones. JSON is easy to read and debug. Where bandwidth is tight, CBOR or Protobuf shrinks messages, but you lose the ability to read them in a terminal.

What this does not solve

A good topic tree does not fix broker capacity, a thundering herd after an outage, or devices that all reconnect at the same second. Add random delay and backoff to reconnect logic, and load test the broker with the device count you expect.


If you are designing the messaging layer for a fleet, book a discovery call, or see our cloud, apps and dashboards and embedded firmware work.

Tell us what you are building.

A 30-minute discovery call with an engineer. We reply within 48 hours.

Book a discovery call