0
0
IOT Protocolsdevops~15 mins

Wildcard subscriptions (+ and #) in IOT Protocols - Deep Dive

Choose your learning style9 modes available
Overview - Wildcard Subscriptions And
What is it?
Wildcard subscriptions allow devices or clients to listen to multiple topics at once using special symbols instead of listing each topic separately. They are used in messaging systems like MQTT to simplify subscribing to groups of related messages. This means a client can receive messages from many topics with a single subscription. Wildcards help manage communication efficiently in systems with many topics.
Why it matters
Without wildcard subscriptions, clients would need to subscribe to each topic individually, which is tedious and inefficient, especially in large IoT networks. This would increase network traffic and complexity, making it harder to scale and maintain systems. Wildcards solve this by enabling flexible, concise subscriptions that reduce overhead and improve responsiveness.
Where it fits
Learners should first understand basic messaging concepts and topic-based publish/subscribe models. After mastering wildcards, they can explore advanced topic filtering, security policies for subscriptions, and optimizing message routing in IoT systems.
Mental Model
Core Idea
Wildcard subscriptions let you listen to many related topics at once by using special symbols that match multiple topic names.
Think of it like...
It's like using a TV remote to switch channels by genre instead of picking each channel number one by one; you press a button that covers all sports channels instead of selecting each sports channel separately.
Topics:
  home/kitchen/temperature
  home/kitchen/humidity
  home/livingroom/temperature

Subscription with wildcards:
  home/+/temperature  → matches home/kitchen/temperature and home/livingroom/temperature
  home/#              → matches all topics starting with home/

Diagram:
  home
  ├─ kitchen
  │  ├─ temperature
  │  └─ humidity
  └─ livingroom
     └─ temperature
Build-Up - 7 Steps
1
FoundationUnderstanding Topics in Messaging
🤔
Concept: Topics are labels or addresses where messages are sent and received in publish/subscribe systems.
In messaging systems like MQTT, messages are sent to topics, which are like channels or categories. Clients subscribe to topics to receive messages sent there. For example, a sensor might publish temperature data to the topic 'home/kitchen/temperature'.
Result
Learners understand that topics organize messages and that subscribing to a topic means receiving messages sent to it.
Knowing what topics are is essential because wildcards work by matching these topic names.
2
FoundationBasic Subscription Without Wildcards
🤔
Concept: Clients subscribe to exact topic names to receive messages only from those topics.
If a client wants temperature data from the kitchen, it subscribes to 'home/kitchen/temperature'. It will not receive messages from 'home/livingroom/temperature' or any other topic.
Result
Subscription is precise but requires multiple subscriptions to cover many topics.
Understanding exact subscriptions shows why wildcards are needed to simplify listening to many topics.
3
IntermediateSingle-Level Wildcard '+' Usage
🤔Before reading on: do you think '+' matches multiple levels or just one level in a topic? Commit to your answer.
Concept: The '+' wildcard matches exactly one level in a topic hierarchy.
Using '+' in a subscription replaces one topic level. For example, 'home/+/temperature' matches 'home/kitchen/temperature' and 'home/livingroom/temperature' but not 'home/kitchen/inside/temperature'.
Result
Clients can subscribe to multiple topics that share the same structure except for one level.
Knowing '+' matches exactly one level helps control which topics are included without being too broad.
4
IntermediateMulti-Level Wildcard '#' Usage
🤔Before reading on: does '#' match zero or more topic levels, or just one? Commit to your answer.
Concept: The '#' wildcard matches zero or more levels at the end of a topic filter.
Using '#' at the end of a subscription matches all topics starting with the preceding path. For example, 'home/#' matches 'home/kitchen/temperature', 'home/livingroom/humidity', and even 'home'.
Result
Clients can subscribe broadly to all topics under a certain path.
Understanding '#' allows flexible, broad subscriptions that cover many topics with one filter.
5
IntermediateCombining Wildcards in Subscriptions
🤔Before reading on: can '+' and '#' be used together in one subscription? Predict how they combine.
Concept: Wildcards '+' and '#' can be combined in topic filters to create precise or broad subscriptions.
For example, 'home/+/+' matches topics with exactly three levels starting with 'home', like 'home/kitchen/temperature'. 'home/+/humidity/#' matches topics starting with 'home', then any single level, then 'humidity', and any number of levels after that.
Result
Clients can tailor subscriptions to complex topic structures.
Knowing how to combine wildcards enables powerful filtering to balance specificity and coverage.
6
AdvancedWildcard Subscription Limitations and Rules
🤔Before reading on: do you think wildcards can be used anywhere in the topic filter or only in specific positions? Commit to your answer.
Concept: Wildcards have specific placement rules and limitations in topic filters.
The '+' wildcard can appear anywhere in the topic filter but only replaces one level. The '#' wildcard must be the last character and must be preceded by a topic level separator or be alone. For example, 'home/#' is valid, but 'home/#/temperature' is invalid.
Result
Learners understand correct wildcard usage to avoid subscription errors.
Knowing these rules prevents common mistakes that cause subscriptions to fail or behave unexpectedly.
7
ExpertPerformance and Security Implications of Wildcards
🤔Before reading on: do you think using broad wildcards always improves performance? Commit to your answer.
Concept: Using wildcards affects message routing performance and security policies in IoT systems.
Broad wildcard subscriptions like '#' can cause clients to receive many messages, increasing processing load and network traffic. They can also expose clients to messages they shouldn't access if security policies are not strict. Therefore, careful design balances wildcard use with system performance and security.
Result
Learners appreciate the trade-offs in wildcard subscription design.
Understanding these impacts helps design scalable, secure IoT messaging systems.
Under the Hood
When a client subscribes with a wildcard, the broker interprets the wildcard symbols to match topic strings dynamically. The '+' wildcard matches exactly one topic level by checking the position in the topic hierarchy, while the '#' wildcard matches all remaining levels from its position. The broker uses these rules to route incoming messages to all clients whose subscriptions match the message topic.
Why designed this way?
Wildcards were introduced to reduce the complexity and overhead of subscribing to many topics individually. The '+' and '#' symbols were chosen for their simplicity and clear semantics, allowing flexible yet predictable matching. Alternatives like regex were rejected for being too complex and costly to process in resource-constrained IoT environments.
Client Subscription: home/+/temperature
Broker matches:
  home/kitchen/temperature  ✔
  home/livingroom/temperature  ✔
  home/kitchen/humidity  ✘

Client Subscription: home/#
Broker matches:
  home/kitchen/temperature  ✔
  home/livingroom/humidity  ✔
  home  ✔

Flow:
[Client] --subscribe--> [Broker]
[Broker] --matches topic with wildcards--> [Message routing to clients]
Myth Busters - 4 Common Misconceptions
Quick: Does '+' match multiple topic levels or just one? Commit to your answer.
Common Belief:The '+' wildcard matches multiple topic levels at once.
Tap to reveal reality
Reality:The '+' wildcard matches exactly one topic level, no more, no less.
Why it matters:Misunderstanding '+' leads to incorrect subscriptions that miss messages or receive unintended ones.
Quick: Can '#' be used anywhere in the topic filter? Commit to your answer.
Common Belief:The '#' wildcard can be placed anywhere in the topic filter to match multiple levels.
Tap to reveal reality
Reality:The '#' wildcard must be the last character in the topic filter and cannot appear in the middle.
Why it matters:Placing '#' incorrectly causes subscription errors or ignored subscriptions.
Quick: Does using '#' always improve system performance? Commit to your answer.
Common Belief:Using '#' wildcard subscriptions always makes message handling more efficient.
Tap to reveal reality
Reality:Using '#' can increase message load on clients and brokers, reducing performance if overused.
Why it matters:Overusing broad wildcards can overwhelm clients and networks, causing delays or crashes.
Quick: Does subscribing with wildcards guarantee security isolation? Commit to your answer.
Common Belief:Wildcard subscriptions automatically enforce security boundaries by limiting topic access.
Tap to reveal reality
Reality:Wildcards do not enforce security; access control must be configured separately to prevent unauthorized message reception.
Why it matters:Assuming wildcards secure topics can lead to data leaks and security breaches.
Expert Zone
1
Some brokers optimize wildcard matching internally using prefix trees to speed up routing, which affects subscription performance.
2
Using wildcards in high-frequency topics can cause message storms on clients, requiring careful load balancing.
3
Security policies often need to be topic-level aware to prevent wildcard subscriptions from bypassing restrictions.
When NOT to use
Avoid wildcards when precise control over message flow is needed or when security policies require strict topic isolation. Instead, use exact topic subscriptions or implement topic aliasing and filtering at the client side.
Production Patterns
In production, wildcard subscriptions are often combined with topic namespaces to segment devices by location or function. Brokers may limit wildcard usage per client to prevent abuse. Monitoring tools track wildcard subscription impact on message throughput and latency.
Connections
Regular Expressions
Wildcard subscriptions are a simplified form of pattern matching similar to regular expressions.
Understanding wildcards helps grasp how pattern matching works in many systems, but wildcards are designed to be lightweight and efficient compared to full regex.
File System Globbing
Wildcard subscriptions resemble file system glob patterns used to match multiple files with symbols like '*' and '?'.
Knowing file globbing patterns clarifies how wildcards select multiple topics, showing a common pattern across computing.
Radio Frequency Channel Scanning
Wildcard subscriptions are like scanning multiple radio channels at once instead of tuning to one frequency.
This connection shows how listening broadly versus narrowly applies in both wireless communication and messaging systems.
Common Pitfalls
#1Using '#' wildcard in the middle of a topic filter.
Wrong approach:home/#/temperature
Correct approach:home/#
Root cause:Misunderstanding that '#' must be the last character in the topic filter.
#2Expecting '+' to match multiple topic levels.
Wrong approach:home/+/+/temperature
Correct approach:home/+/temperature
Root cause:Believing '+' can replace more than one topic level leads to incorrect subscription patterns.
#3Subscribing broadly with '#' without considering message volume.
Wrong approach:home/#
Correct approach:home/kitchen/#
Root cause:Not accounting for the high message load caused by very broad wildcard subscriptions.
Key Takeaways
Wildcard subscriptions use '+' and '#' to match one or many topic levels, simplifying message listening.
The '+' wildcard matches exactly one topic level, while '#' matches zero or more levels but only at the end.
Proper use of wildcards reduces subscription complexity but requires understanding placement rules to avoid errors.
Overusing broad wildcards can harm system performance and security if not managed carefully.
Wildcard subscriptions are a practical, efficient pattern matching tool essential for scalable IoT messaging.