Application Protocols · Study deck

HTTP Pitfalls: Migration and Recovery

HTTP looks simple until a small device pays for every poll, handshake, retry, oversized payload, and reconnect storm.

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: 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.
  • Explain: 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.
  • design retry and recovery behavior with measurable limits
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.
  • Per-update overhead: MQTT PUBLISH header 14 bytes, binary GPS payload 9 bytes, keep-alive 2 bytes every 60 seconds.

Numbers to remember

9 bytesbinary GPS payload 9 bytes, keep-alive 2 bytes every 60 seconds.
2 bytesbinary GPS payload 9 bytes, keep-alive 2 bytes every 60 seconds.
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

How It Works: HTTP Connection Lifecycle

The client sends SYN, the server replies with SYN-ACK, and the client finishes with ACK; then: Step 2: TLS 1.2 handshake (2 RTT).

  • The client sends GET /sensor/data, then the server returns 200 OK and the payload; and finish with: Total before data arrives: typically 4 to 5 RTT.
  • 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.
iotclass.org

Deck summary

Key takeaways

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

  • 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.
  • Process chunk by chunk and cap the total accepted size instead of trusting the sender to stop.
  • The client sends SYN, the server replies with SYN-ACK, and the client finishes with ACK; then: Step 2: TLS 1.2 handshake (2 RTT).
iotclass.org

Retrieval practice

Recall check 1 of 4

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

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

iotclass.org

Retrieval practice

Recall check 2 of 4

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

Q2Place each HTTP connection concern where it lives so you can cut handshake waste without creating a blocked queue or exhausting a constrained gateway.

ATCP and TLS Setup Cost
BHTTP/1.1 Head-of-Line Queue
CKeep-Alive Lifetime Policy
DBounded Connection Pool
Show answer

Answer: A Place each HTTP connection concern where it lives so you can cut handshake waste without creating a blocked queue or exhausting a constrained gateway.

iotclass.org

Retrieval practice

Recall check 3 of 4

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

Q3An 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
BJSON payload encoding is too slow; switch to binary format like CBOR
CThe gateway CPU cannot handle 50 concurrent TLS sessions; upgrade the hardware
DTLS handshake overhead adds 400-600ms per connection.
Show answer

Answer: D

iotclass.org

Retrieval practice

Recall check 4 of 4

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

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

ASet a fixed 30-second delay before all clients reconnect
BDisable automatic reconnection and require users to manually refresh
CUse exponential backoff with random jitter.
DIncrease server capacity to handle all 500 simultaneous TLS handshakes
Show answer

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

iotclass.org

Print reference

Answers

Answer key.

  1. 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.
  2. A · Place each HTTP connection concern where it lives so you can cut handshake waste without creating a blocked queue or exhausting a constrained gateway.
  3. D
  4. C · Exponential backoff with random jitter spreads reconnection attempts over time.
iotclass.org