Networking basics for system design
Overview
You don’t need to be a network engineer to design systems, but a few networking ideas decide real trade-offs: why a chat app keeps connections open, why a game uses UDP, why talking to a far-away region is slow. This lesson covers the minimum you need.
Layers, each with one job
Networking is built in layers. Each layer relies on the one below and adds one job.
- IP moves packets between machines using IP addresses. It makes no promises: packets can be lost, duplicated or arrive out of order.
- TCP or UDP add ports, so one machine can run many services (web on 443, Postgres on 5432), and define delivery rules.
- TLS encrypts the data and proves the server’s identity with a certificate.
- Application protocols such as HTTP, gRPC and WebSocket define what the bytes mean.
TCP: reliable and ordered
TCP turns IP’s unreliable packets into a reliable stream of bytes. Before sending data, client and server perform a three-way handshake (SYN, SYN-ACK, ACK). After that, TCP:
- numbers every byte and resends anything that is lost,
- delivers data in order,
- slows down when the network is congested.
The cost is time. The handshake takes one round trip, and TLS adds at least one more. On a 100 ms intercontinental link, opening a fresh HTTPS connection can take 200–300 ms before the first byte of the request. That is why clients and servers reuse connections (keep-alive and connection pools) instead of opening a new one per request.
TCP’s ordering also has a downside called head-of-line blocking: if one packet is lost, everything behind it waits until it is resent.
UDP: fast and lossy
UDP just sends packets. There is no handshake, no resending and no ordering. That sounds worse, but it is exactly right when late data is useless:
- Video and voice calls: a lost frame should be skipped, not replayed half a second later.
- Online games: only the latest player position matters.
- DNS lookups: one small question, one small answer; if it’s lost, just ask again.
TLS and HTTPS
TLS encrypts traffic so nobody between client and server can read or change it, and uses certificates so the client knows it is talking to the real server. HTTPS is simply HTTP over TLS. Today almost all traffic should be encrypted, including traffic between your own services inside a data centre.
A practical design point: TLS is often terminated at the load balancer or API gateway, which decrypts the request and forwards it to the app servers. That centralises certificates and saves the app servers some CPU.
HTTP versions in one minute
- HTTP/1.1: one request at a time per connection, so browsers open several connections in parallel.
- HTTP/2: many requests share one TCP connection at the same time (multiplexing), with compressed headers. Still suffers from TCP head-of-line blocking.
- HTTP/3: runs over QUIC, which is built on UDP and adds its own reliability and encryption. A lost packet only delays its own stream, and connections set up faster.
For design interviews, “HTTPS” is usually enough; mention HTTP/2 or gRPC when many small calls between services matter, and HTTP/3 when mobile users on poor networks matter.
Getting updates from the server
Plain HTTP is request/response: the server only speaks when asked. When the server needs to push updates, there are four common options:
| Option | How it works | Good for |
|---|---|---|
| Short polling | Client asks every few seconds | Rare updates, simple setups |
| Long polling | Client asks; server holds the request open until there is news | Moderate real-time needs, old clients |
| Server-sent events (SSE) | One long-lived HTTP response that streams events | One-way feeds: notifications, live scores |
| WebSocket | A persistent two-way connection | Chat, collaborative editing, live games |
Persistent connections are not free. A chat service with 10 million online users needs servers that hold 10 million open connections, and a way to find which server holds a given user’s connection. You will design exactly that in the chat case study.
DNS in a little more depth
You met DNS in the previous lesson. Three details matter for design:
- Record types:
A/AAAAmap a name to an IPv4/IPv6 address;CNAMEpoints one name at another, which is how you hand a domain to a CDN. - TTL: a short TTL (say 60 seconds) lets you move traffic quickly during an incident; a long TTL reduces lookups but slows down changes.
- Traffic steering: managed DNS services can return different answers by user location (to send users to the nearest region) or by health (to fail over).
Latency across distance
Light in fibre covers roughly 200 km per millisecond. A round trip between Europe and the US East Coast is therefore at least ~60–80 ms, and real routes are longer. If a page needs five sequential calls across that distance, the user waits half a second before anything else happens. Designs fight distance by:
- serving static content from a CDN close to the user,
- running servers in several regions,
- cutting the number of round trips (batching, fewer sequential calls, connection reuse).
Recap
IP moves packets, TCP makes them reliable and ordered, UDP keeps them fast and simple, and TLS keeps them private. HTTP runs on top, in versions that reduce round trips and blocking. When the server must push data, use SSE or WebSockets and plan for many open connections. And remember that distance has a fixed cost: the fastest request is the one that never crosses an ocean.
Pick the protocol
For each feature, choose a protocol or connection style (for example HTTP request/response, WebSocket, UDP-based protocol, or HTTP with polling) and give one reason: (a) loading a product page, (b) a live multiplayer racing game sending player positions 30 times per second, (c) a chat app that must show new messages instantly, (d) a dashboard that refreshes sales totals every 5 minutes, (e) a video call.
(a) Product page:
(b) Racing game positions:
(c) Chat messages:
(d) Sales dashboard:
(e) Video call:(a) Product page: HTTP(S) request/response. The client asks once and gets one
answer; it is cacheable and works with CDNs and load balancers.
(b) Racing game positions: UDP (or a UDP-based game protocol). A lost position is
useless once the next one arrives 33 ms later, so resending old packets (TCP)
would only add delay.
(c) Chat: WebSocket. The server must push new messages the moment they arrive,
and a long-lived two-way connection avoids constant polling.
(d) Sales dashboard: plain HTTP polling every 5 minutes is fine. Updates are rare
and slightly stale data is acceptable, so a persistent connection is not worth it.
(e) Video call: UDP-based media (WebRTC uses RTP over UDP). Low delay matters more
than receiving every packet; a lost frame is skipped, not resent.Summary
- An endpoint is an IP address plus a port; DNS turns names into IP addresses.
- TCP gives reliable, ordered delivery after a handshake; UDP is faster and simpler but may lose or reorder packets.
- TLS encrypts the connection; HTTPS is HTTP over TLS.
- HTTP/1.1 and HTTP/2 run over TCP; HTTP/3 runs over QUIC, which is built on UDP.
- WebSockets keep a two-way connection open so the server can push data; plain HTTP only answers requests.