What’s the Real Difference Between HTTP Keep‑Alive and TCP Keepalive?
This article explains how MySQL stores NULL values and clarifies the distinct mechanisms of HTTP Keep‑Alive (application‑level long connections) versus TCP Keepalive (kernel‑level health checks), detailing their implementations, usage, and practical considerations.
During a ByteDance interview, a candidate was asked two questions: how MySQL stores NULL values and the difference between HTTP Keep‑Alive and TCP Keepalive. The article revisits these topics.
MySQL NULL storage
The first question tests understanding of MySQL record storage. In MySQL, a NULL value is represented by a bitmap in the record header; the actual column data is omitted, saving space while allowing the engine to distinguish NULL from zero or empty strings.
HTTP Keep‑Alive
HTTP Keep‑Alive is an application‑level feature that allows a single TCP connection to carry multiple HTTP request/response pairs, avoiding the overhead of establishing a new TCP connection for each request. In HTTP/1.0 it must be enabled via the Connection: Keep-Alive header; HTTP/1.1 enables it by default. The server can close the connection with Connection: close. Keep‑Alive reduces latency and enables HTTP pipelining, where a client can send several requests without waiting for each response, though the server still replies in order.
Web servers typically configure a keepalive_timeout (e.g., 60 seconds) to close idle connections and free resources.
TCP Keepalive
TCP Keepalive is a kernel‑level mechanism that periodically sends probe packets on an idle TCP connection to verify that the peer is still reachable. If the peer responds, the keepalive timer resets; if several probes fail, the connection is considered dead. Applications must enable it by setting the socket option SO_KEEPALIVE.
Summary
HTTP Keep‑Alive (application‑level) and TCP Keepalive (kernel‑level) serve different purposes: the former prolongs a TCP connection for multiple HTTP exchanges, while the latter monitors connection liveness when no data is exchanged.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
