Client-server vs publish-subscribe models in IOT Protocols - Performance Comparison
We want to understand how the work done by IoT communication models grows as more devices join.
Which model handles more devices efficiently as the network grows?
Analyze the message handling in client-server and publish-subscribe models.
// Client-server model
for each client in clients:
server.receive(client.message)
server.send(client.response)
// Publish-subscribe model
for each message in topics:
for each subscriber in message.subscribers:
broker.forward(message, subscriber)
This code shows how messages are processed in each model: client-server handles each client directly, publish-subscribe forwards messages to all subscribers.
- Primary operation: In client-server, server processes each client once.
- How many times: Once per client (n times).
- Primary operation: In publish-subscribe, broker forwards each message to all subscribers.
- How many times: For each message, to all subscribers (n x m times).
As devices increase, work grows differently:
| Input Size (clients or subscribers) | Client-Server Operations | Publish-Subscribe Operations |
|---|---|---|
| 10 | 10 | 100 (10 messages x 10 subscribers) |
| 100 | 100 | 10,000 (100 x 100) |
| 1000 | 1000 | 1,000,000 (1000 x 1000) |
Client-server grows linearly with clients. Publish-subscribe grows much faster because it sends to all subscribers for each message.
Time Complexity: O(n) for client-server, O(n x m) for publish-subscribe
This means client-server work grows directly with number of clients, while publish-subscribe grows with both messages and subscribers.
[X] Wrong: "Publish-subscribe always handles messages as fast as client-server because it uses a broker."
[OK] Correct: The broker must forward each message to every subscriber, which can multiply work a lot as subscribers grow.
Understanding how these models scale helps you explain system choices clearly and shows you think about real-world device growth.
"What if the publish-subscribe model used topic filters to reduce subscribers per message? How would that affect time complexity?"