Application Protocols · Study deck

HTTP Pitfalls: Migration and Recovery

HTTP is the web's way to ask for data and get a reply.

Broker Bex is your guide for this deck.

httpconnectionmanagement
Broker Bex, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Explain: Repeated connection setup dominates this example: changing only the 32-byte payload to 9 bytes saves 23 / 6,972 = 0.33% of counted bytes, whereas reusing the secure connection removes repeated setup.
  • Explain: The difference identifies setup reuse as the lever, while the notes prevent overclaiming: TLS version and resumption alter the exchange, intermediaries limit keep-alive, and early data has replay constraints.
  • Explain: The client sends ClientHello, the server returns ServerHello plus its certificate, the client responds with key exchange plus Finished, and the server completes the handshake with its own Finished.
iotclass.org

Major section

Worked Example: Protocol Migration Cost-Benefit Analysis

Scenario: A fleet management company operates 5,000 GPS trackers on delivery vehicles.

  • Each tracker sends location updates every 30 seconds via HTTPS POST to a cloud API.
  • The CTO notices excessive cellular data costs and asks the engineering team to evaluate alternatives.
  • The byte counts below are illustrative assumptions for the listed components.

Key terms

Neither ratio
Neither ratio is a measured cellular-bandwidth saving.
iotclass.org

Major section

Worked Example: Protocol Migration Cost-Benefit Analysis (continued)

They omit per-packet IP/link framing, TLS record overhead, responses to MQTT keepalives, retransmissions, and cellular billing increments.

  • The per-update byte count combines setup, headers, and payload; scaling it to the fleet reveals why a fresh HTTPS connection is costly.
  • For MQTT, count the publish bytes and keepalive traffic before scaling per-tracker use to fleet cost.
  • Neither ratio is a measured cellular-bandwidth saving.
iotclass.org

Major section

Worked Example: Protocol Migration Cost-Benefit Analysis (continued)

Per-update overhead: MQTT PUBLISH header 14 bytes, binary GPS payload 9 bytes, keep-alive 2 bytes every 60 seconds.

  • Server-initiated updates: current POST-only design no, MQTT subscriptions yes, reused HTTP/2 can carry an SSE response when the client opens one.
  • Key Insight: In the listed-byte model, 32 / 6,972 = 0.46% of each fresh-connection update is the useful payload.
  • Repeated connection setup dominates this example: changing only the 32-byte payload to 9 bytes saves 23 / 6,972 = 0.33% of counted bytes, whereas reusing the secure connection removes repeated setup.
iotclass.org

Major section

Deep Dive: What One HTTPS Request Really Costs

On a battery-powered device over a cellular link, the payload is rarely the expensive part.

  • A 20-byte reading can be preceded by radio wake, TCP connection setup, TLS negotiation, certificate validation, and the HTTP request/response round trip.
  • On the warm path, the established secure connection lets HTTP begin immediately.

Why it matters

0-RTT resumption can send early data immediately from a prior session, but only safe, idempotent requests belong there because early data can be replayed.

A cold HTTPS request pays TCP and TLS setup before HTTP, while a warm keep-alive request can reuse the established secure connection.
A cold HTTPS request pays TCP and TLS setup before HTTP, while a warm keep-alive request can reuse the established secure connection.
iotclass.org

Major section

Deep Dive: What One HTTPS Request Really Costs (continued)

On a 100-300 ms round-trip path, that setup can keep the radio active for seconds before the tiny payload moves.

  • The difference identifies setup reuse as the lever, while the notes prevent overclaiming: TLS version and resumption alter the exchange, intermediaries limit keep-alive, and early data has replay constraints.
  • The TLS 1.3 handshake is one round trip.
  • The other framing detail that trips up gateways is chunked transfer encoding.
iotclass.org

Major section

Deep Dive: What One HTTPS Request Really Costs (continued)

Process chunk by chunk and cap the total accepted size instead of trusting the sender to stop.

  • A practical rollout records idle timeout, heartbeat interval, reconnect rate, radio-on time, and session-reuse rate, then chooses the cheapest setting that keeps useful sessions alive.
  • TLS 1.2 usually needs another round trip for the extra key-exchange step.
  • For a field review, keep one cold-start trace and one warm-session trace.
iotclass.org

Major section

Summary

HTTP polling drains batteries rapidly - use MQTT or CoAP for frequent updates.

  • TLS handshake overhead dominates communication time - use connection pooling.
  • Connection Management: After link reuse, limit retries, errors, and payload size.
  • One failure should not flood the link.
  • Error Handling and Safety: Streaming limits control memory, while client count and update direction help choose polling, server events, or WebSockets.
iotclass.org

Major section

How It Works: HTTP Connection Lifecycle

The client sends SYN, the server replies with SYN-ACK, and the client finishes with ACK.

  • The client sends ClientHello, the server returns ServerHello plus its certificate, the client responds with key exchange plus Finished, and the server completes the handshake with its own Finished.
  • The client sends GET /sensor/data, then the server returns 200 OK and the payload.
  • On a 100 ms latency cellular link: The 450 ms first request includes connection setup; reuse removes that setup from later requests.
  • With HTTP/2:: HTTP/2 pays its setup once, then sends concurrent requests through one connection with compressed headers.
iotclass.org

Major section

Concept Relationships

Solutions: WebSocket allows two-way data; server events push one way.

  • CoAP has a lighter link.
  • TCP three-way handshake adds 1.5 RTT.
  • TLS 1.2 handshake adds 2 RTT (TLS 1.3 adds 1 RTT).
  • Each HTTP/1.1 connection has overhead ~8KB RAM per connection.
iotclass.org

Deck summary

Key takeaways

Scenario: A fleet management company operates 5,000 GPS trackers on delivery vehicles.

  • They omit per-packet IP/link framing, TLS record overhead, responses to MQTT keepalives, retransmissions, and cellular billing increments.
  • Per-update overhead: MQTT PUBLISH header 14 bytes, binary GPS payload 9 bytes, keep-alive 2 bytes every 60 seconds.
  • On a battery-powered device over a cellular link, the payload is rarely the expensive part.
  • On a 100-300 ms round-trip path, that setup can keep the radio active for seconds before the tiny payload moves.
iotclass.org

Retrieval practice

Recall check 1 of 4

Broker Bex says: answer from memory, then check your reasoning.

Q1An HTTP telemetry path has high connection cost. When is a move to MQTT justified?

APromote MQTT after the protocol comparison because its recovery and HTTP reuse are established by the promotion result.
BAfter skipping connection reuse tests on the existing HTTP path
CAfter measuring optimized HTTP against MQTT, including failure recovery
DAfter removing failure tests from both protocol deployment plans
Show answer

Answer: C The chapter asks for a measured comparison and recovery evidence.

iotclass.org

Retrieval practice

Recall check 2 of 4

Broker Bex says: answer from memory, then check your reasoning.

Q2Complete the HTTP connection management for IoT polling:

Asession = requests.Session()
Bsession = requests.Connection()
Csession = requests.create_session()
Dsession = requests.HTTPClient()
Show answer

Answer: A Using requests.Session() enables HTTP keep-alive connection reuse, reducing TCP handshake overhead for repeated API calls. Always set timeout to prevent hanging on unreachable IoT devices. Session headers persist across all requests.

Q3What adds transport and security round trips before a fresh HTTP connection can carry a request?

AHTTP/1.1 Head-of-Line Queue
BKeep-Alive Lifetime Policy
CTCP and TLS Setup Cost
DBounded Connection Pool
Show answer

Answer: C A fresh connection pays transport and security round trips before an HTTP request can carry useful application data.

iotclass.org

Retrieval practice

Recall check 3 of 4

Broker Bex says: answer from memory, then check your reasoning.

Q4An IoT gateway sends temperature readings from 50 sensors to a cloud API using HTTP POST requests -- one request per sensor every 10 seconds. Each request creates a new TCP+TLS connection. The gateway's latency is unexpectedly high (800ms per request) despite a fast network. What is the primary cause and best fix?

AThe cloud API is rate-limiting the gateway; request higher rate limits
BRepeated TCP+TLS handshakes add round trips; use pooled HTTP keep-alive connections.
CJSON payload encoding is too slow; switch to binary format like CBOR
DThe gateway CPU cannot handle 50 concurrent TLS sessions; upgrade the hardware
Show answer

Answer: B see answers page

iotclass.org

Retrieval practice

Recall check 4 of 4

Broker Bex says: answer from memory, then check your reasoning.

Q5After a server restart, 500 IoT dashboard WebSocket clients all attempt to reconnect simultaneously, crashing the server. What reconnection strategy prevents this "thundering herd" problem?

AUse exponential backoff with random jitter to stagger client retries
BSet the same fixed 30-second delay for every reconnecting client
CDisable automatic reconnection and require manual dashboard refresh
DIncrease server capacity to absorb simultaneous reconnect attempts
Show answer

Answer: A Exponential backoff with random jitter spreads reconnection attempts over time.

iotclass.org

Print reference

Answers 1 of 2

Answer key.

  1. C · The chapter asks for a measured comparison and recovery evidence.
  2. A · Using requests.Session() enables HTTP keep-alive connection reuse, reducing TCP handshake overhead for repeated API calls. Always set timeout to prevent hanging on unreachable IoT devices. Session headers persist across all requests.
  3. C · A fresh connection pays transport and security round trips before an HTTP request can carry useful application data.
iotclass.org

Print reference

Answers 2 of 2

Answer key.

  1. B · The chapter's connection lifecycle counts 2 RTT for the TLS 1.2 handshake, or 200 ms at 100 ms RTT, in addition to TCP setup and the HTTP exchange. Fifty sensors reporting every 10 seconds produce five requests per second, or 300 requests per minute. HTTP keep-alive with connection pooling avoids repeating TCP and TLS setup for each POST; the exact latency saving depends on RTT, TLS version and intermediaries.
  2. A · Exponential backoff with random jitter spreads reconnection attempts over time.
iotclass.org