Shared subscriptions
MQTT 3.3.1 and 5.0 introduced shared subscriptions to distribute messages across a group of subscribers. In standard MQTT, every subscriber to a topic receives a copy of each message. With shared subscriptions, messages are delivered to only one member of a consumer group, enabling horizontal scaling without duplicate processing.
How it works
A shared subscription uses a special topic filter prefix to group multiple clients into a consumer group. The MQTT broker delivers each incoming message to exactly one member of the group, rather than broadcasting it to all subscribers.
Topic filter format:
$share/<consumer-group>/<topic>Component | Description | Example |
| Fixed prefix that identifies a shared subscription |
|
| Name of the consumer group |
|
| Standard MQTT topic to subscribe to |
|
For example, the topic filter $share/group1/orders/new subscribes to the orders/new topic as part of consumer group group1.
Message distribution: The broker selects a recipient for each message using one of the following algorithms:
Algorithm | Behavior |
Polling | Delivers messages to group members in round-robin order, cycling through each member in turn. |
Random | Selects a random group member for each message, providing even distribution over time. |
Hashing | Routes messages to group members based on a hash value, distributing the load across the group. |
Use cases
Shared subscriptions address three common scaling problems:
Message throughput exceeds single-client capacity. When an individual subscriber cannot keep up with the message rate on a topic, distribute the load across multiple consumers in a shared group.
Backend workers must scale horizontally. Worker applications that ingest MQTT data streams can add or remove instances without changing the publishing side.
A single point of failure is unacceptable. Running multiple subscriber instances in a consumer group provides redundancy. If one client disconnects, the remaining members continue processing messages.
Limitations
Available only on Professional Edition and Platinum Edition instances. To enable shared subscriptions, submit a ticket.
Shared subscriptions support only QoS 1 (at-least-once delivery). Duplicate messages may occur during slow client consumption, client reconnections, server upgrades, or server breakdowns.
The maximum number of consumer groups per instance is 5,000.
A shared subscription consumer group name must not exceed 16 characters. The consumer group name is the
<consumer-group-name>component in the subscription format$share/<consumer-group-name>/<Topic>. For example, in$share/group1/orders/new, the consumer group name isgroup1. This name is different from the Group ID in the Client ID used for the connection.
Example: distribute orders across worker nodes
The following example shows how multiple backend worker nodes process incoming orders published to the orders/new topic using a shared subscription.
Step 1: Subscribe
Each worker node subscribes with the shared subscription prefix:
SUBSCRIBE
Topic Filter: $share/group1/orders/newAll workers that use the same consumer group name (group1) form a single consumer group. A consumer group name must not exceed 16 characters.
Step 2: Publish
A publisher sends a new order to the orders/new topic:
PUBLISH
Topic: orders/new
Payload: { "order_id": "xyz", "product": "ABC" }Step 3: Receive
The broker delivers this message to exactly one worker in group1. The next message goes to another worker (based on the distribution algorithm), spreading the processing load evenly across all online members.
Tip: When subscribing from a command-line tool such asmosquitto_subormqttx, wrap the topic filter in single quotes to prevent shell expansion of the$shareprefix:
What's next
Send and receive messages -- Publish and subscribe to standard (non-shared) topics.
Manage instances -- Create or upgrade to a Professional or Platinum Edition instance.