Q: How to design MQTT topic hierarchies and payload formats for large-scale IoT deployments?
Answer
MQTT topic hierarchy best practices: ////. Example: factory1/zoneA/sensor/temp001/temperature. Use wildcards (# + single-level) for subscriptions. Payload format: use JSON for human readability; Protocol Buffers (protobuf) or CBOR for bandwidth-constrained links (50-80% smaller than JSON). Implement schema versioning in the payload (schema_version field). For Sparkplug B: use the standard payload format with metrics arrays. Topic design rules: (1) No spaces or special characters. (2) Consistent depth. (3) Include device type for filtering. (4) Separate command topics from data topics: factory1/sensor/temp001/cmd vs /data. For large scale (>10K devices): use shared subscriptions (AWS IoT Core $share/) for load-balanced MQTT consumers. Implement last-will-and-testament (LWT) for device death detection.
Filed under: FAQ