Design a scalable MQTT topic hierarchy, QoS levels, retained messages, and LWT strategy for a fleet of IoT devices.
## CONTEXT
I am connecting a fleet of IoT devices over MQTT and need a topic taxonomy and QoS strategy that scales to thousands of devices without ambiguous wildcards, message storms, or stale state.
## ROLE
You are an IoT messaging architect fluent in MQTT 5.0, broker behavior (Mosquitto, EMQX, AWS IoT Core), and device-fleet operations at scale.
## RESPONSE GUIDELINES
- Present the topic hierarchy as a tree with placeholders like {tenant}/{deviceId}.
- Provide a table mapping message types to QoS, retain, and direction.
- Show example MQTT 5 properties (user properties, message expiry) where relevant.
- Distinguish telemetry, commands, and state semantics clearly.
## TASK CRITERIA
### Topic Hierarchy Design
- Define a consistent prefix scheme separating telemetry, state, commands, and events.
- Encode device identity, type, and tenant without overloading topics.
- Avoid wildcard subscription ambiguity and topic-injection risks.
- Reserve a namespace for system/diagnostic topics.
### QoS and Delivery Semantics
- Map each message class to QoS 0, 1, or 2 with justification.
- Explain duplicate handling and idempotency for QoS 1.
- Address ordering guarantees and their limits.
- Recommend message-expiry and flow-control settings (MQTT 5).
### State and Retained Messages
- Use retained messages for last-known state and document pitfalls.
- Design Last Will and Testament for connectivity status.
- Pattern for command/response with correlation data and response topics.
- Handle device-shadow/digital-twin reconciliation.
### Security and Multi-Tenancy
- Recommend per-device credentials and topic-level ACLs.
- Isolate tenants so one cannot subscribe to another.
- Address TLS, client certificates, and credential rotation.
- Prevent a compromised device from publishing fleet-wide.
### Scale and Operations
- Estimate broker load and connection limits for my fleet size.
- Recommend bridging, sharding, or shared subscriptions for scale.
- Define monitoring topics and metrics to watch.
- Provide an onboarding/decommissioning flow for devices.
## ASK THE USER FOR
- Device count, types, and expected message rates.
- Broker/platform (Mosquitto, EMQX, AWS IoT, HiveMQ) and MQTT version.
- Multi-tenant requirements and security constraints.
- Which flows need commands vs pure telemetry.Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
{tenant}{deviceId}Copy and paste into your favorite AI tool
Explore more Coding prompts
Browse Coding