0
0
IOT Protocolsdevops~5 mins

Client-server vs publish-subscribe models in IOT Protocols - Performance Comparison

Choose your learning style9 modes available
Time Complexity: Client-server vs publish-subscribe models
O(n) for client-server, O(n x m) for publish-subscribe
Understanding Time Complexity

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?

Scenario Under Consideration

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.

Identify Repeating Operations
  • 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).
How Execution Grows With Input

As devices increase, work grows differently:

Input Size (clients or subscribers)Client-Server OperationsPublish-Subscribe Operations
1010100 (10 messages x 10 subscribers)
10010010,000 (100 x 100)
100010001,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.

Final Time Complexity

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.

Common Mistake

[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.

Interview Connect

Understanding how these models scale helps you explain system choices clearly and shows you think about real-world device growth.

Self-Check

"What if the publish-subscribe model used topic filters to reduce subscribers per message? How would that affect time complexity?"