intermediate
TCP and UDP
Compare reliable ordered TCP streams with lightweight UDP datagrams, including handshakes, retransmission, congestion control, and QUIC usage.
TCP delivers reliable, ordered byte streams with connection setup, acknowledgments, retransmission, and congestion control. UDP sends connectionless datagrams with no delivery guarantees — lower overhead, suitable for real-time or loss-tolerant traffic. HTTP/3 runs over QUIC, which uses UDP with built-in encryption and multiplexing.
Client Server
|---- SYN -------------->|
|<--- SYN-ACK -----------|
|---- ACK -------------->|
|==== data stream ======>|
| Property | TCP | UDP | |----------|-----|-----| | Reliability | Retransmits lost segments | Best effort | | Ordering | In-order delivery | Application handles order | | Connection | 3-way handshake | None | | Typical use | HTTP/1.1, HTTP/2, databases | DNS, QUIC, VoIP |
On interviews: explain why a Node service opening many outbound TCP connections can hit ephemeral port limits; when UDP is acceptable; and how QUIC changes head-of-line blocking compared to TCP.
Common pitfalls: assuming "async HTTP" removes TCP handshake cost; ignoring TIME_WAIT socket accumulation; using UDP where ordering matters without application logic.
The trade-off is reliability and fairness versus latency and simplicity — pick the transport that matches your failure tolerance.
Checklist:
- Name the TCP handshake and what RTT adds.
- Contrast UDP datagrams with TCP streams.
- Mention QUIC/HTTP/3 over UDP.
- Tie connection reuse to latency in Node agents.