When HTTP is appropriate for IoT in IOT Protocols - Time & Space Complexity
We want to understand how the time it takes to send data using HTTP in IoT devices changes as the number of messages grows.
How does the communication cost grow when many IoT devices use HTTP?
Analyze the time complexity of the following code snippet.
// Pseudocode for sending sensor data via HTTP
for each device in devices:
for each data_point in device.data:
http_post(server_url, data_point)
This code sends each data point from every device to a server using HTTP POST requests.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Sending HTTP POST requests for each data point.
- How many times: Once for every data point of every device.
As the number of devices or data points grows, the total HTTP requests grow proportionally.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 devices x 10 data points | 100 HTTP requests |
| 100 devices x 10 data points | 1,000 HTTP requests |
| 100 devices x 100 data points | 10,000 HTTP requests |
Pattern observation: The number of HTTP requests grows directly with the total data points sent.
Time Complexity: O(n)
This means the time to send data grows in a straight line with the number of data points.
[X] Wrong: "Sending data with HTTP is always slow regardless of data size."
[OK] Correct: The time depends on how many messages are sent, not just the protocol. Small amounts of data can be sent quickly.
Understanding how communication scales helps you design IoT systems that work well as they grow. This skill shows you can think about real-world device limits.
"What if we batch multiple data points into one HTTP request? How would the time complexity change?"