Transport and sockets are the practical interface to the network: ports, connections, streams, datagrams, and backpressure. Understanding TCP vs UDP and basic socket behavior prevents a lot of subtle production issues. Example: TCP guarantees ordered delivery but can amplify latency under loss; UDP trades guarantees for control and speed.

TCP vs UDP

The two transports are the real choice at this layer; Sockets is the file-like API you program either one through, not a third option.

PropertyTCPUDP
ConnectionConnection-oriented — 3-way handshake before dataConnectionless — no handshake, no state
DeliveryGuaranteed; retransmits lost segmentsBest-effort; a lost datagram is gone
OrderingIn-order via sequence numbersNone; datagrams can arrive out of order
Flow / congestion controlYes — sliding window, slow-start, AIMDNone; the app must pace itself
FramingByte stream — no message boundaries (handle partial reads)Datagrams — message boundaries preserved
Overhead20+ byte header plus per-connection state8-byte header, no state
LatencyHigher — handshake round-trip and ACK waitsLower — send and forget
Fan-outPoint-to-point onlyUnicast, plus broadcast and multicast
Reach for it whenCorrectness needs delivery: HTTP, databases, file transferLatency beats reliability, or the app handles loss: streaming, gaming, DNS, QUIC, telemetry

Default to TCP: most applications need its ordered, reliable byte stream and can absorb the handshake cost. Reach for UDP when a late packet is worse than a lost one (real-time media, gaming), when the payload is a single small request/response (DNS), or when you need one-to-many fan-out — accepting that any reliability or ordering you still want must be built on top, as QUIC (HTTP/3) does.

References

3 items under this folder.