map / networking / tcp
Networking · principle 3 of 6
TCP handshake & congestion
TCP spends one round trip to open a connection and then ramps up its sending window, so new connections are slow by design.
01 · Why it’s true
IP can drop, duplicate, or reorder packets. TCP builds a reliable, ordered byte stream on top: it numbers bytes, the receiver acknowledges what arrived, and the sender retransmits what wasn’t acknowledged.
Before any data flows, the two sides exchange SYN and SYN-ACK to agree on starting sequence numbers — one round trip. And because the sender doesn’t know how much the network can carry, it starts with a small congestion window and grows it as acknowledgements arrive, backing off when it sees loss. New connections are slow by design.
02 · Picture it
03 · In the interview
- Explaining why connection reuse (keep-alive, pooling) matters for latency.
- Reading errors: “connection refused” (a reset — nothing listening) vs “connection timed out” (no reply at all).
- Recognizing packet loss as a latency problem: retransmissions and a shrinking window slow everything down.
04 · Practice question
“Some clients see “connection timed out” to a service, others see “connection refused”. What does each tell you?”
A strong answer covers
- Refused: the host answered with a reset — it’s reachable, but nothing is listening on that port (process down, wrong port).
- Timed out: no answer at all — a firewall or security group dropping packets, a host that’s down, or a routing problem.
- Test a TCP connect from the client side, then check on the server whether the process is listening (
ss -ltn). - If it’s intermittent, look for a few bad backends behind a load balancer, or a full listen queue on a busy server.