bigonotes
System DesignNetworking

Networking Fundamentals

The OSI layers that matter to you (3, 4 and 7), and what happens on the wire when a browser loads a page.

5 min readLast updated

Networking is how machines find each other and exchange data. It's built in layers, each one relying on the one below and hiding its details from the one above. As an application developer you mostly work at the top, but knowing what happens underneath explains a lot of system design: why handshakes cost latency, why connection reuse matters, and why some load balancers are faster than others.

The OSI model#

The OSI model splits networking into seven layers. In practice you only need to reason about three of them: network (3), transport (4) and application (7). The table lists all seven so you can place the names you'll hear, with those three in bold.

Layer Name What it does Examples
7 Application Where your code lives. Defines what the messages mean. HTTP, DNS, SMTP, FTP
6 Presentation Formatting and encryption of data. TLS, JSON, ASCII
5 Session Managing conversations between applications. Sockets
4 Transport How data is delivered between two programs. TCP (reliable), UDP (fast)
3 Network Addressing and routing packets across networks. IP, routers
2 Data link Moving frames between machines on the same local network. Ethernet, MAC addresses, switches
1 Physical Sending raw bits as signals. Fiber, copper, Wi-Fi radio

TLS is often listed at layer 6, but in day-to-day engineering people usually talk about it as sitting between TCP and HTTP. Don't worry about the exact layer number. What matters is that HTTPS is HTTP running over TLS running over TCP.

Layer 3: network#

Layer 3 gets a packet from one machine to another, possibly across many networks. Every device has an IP address, and routers read that address to choose the next hop. See IP Addressing and Routing.

Layer 4: transport#

Once a packet can reach the right machine, layer 4 decides how the data is delivered between two programs on it:

  • TCP: every byte arrives, in order, with no duplicates. It sets up a connection first.
  • UDP: packets may arrive out of order or not at all, but there is no setup and less overhead.

See TCP and UDP.

Layer 7: application#

Layer 7 sits on top. It turns your intent ("fetch this user's profile") into a protocol message, such as an HTTP request, that the lower layers know how to carry. See Web and Real-Time Protocols.

Each layer wraps the one above#

The three layers work together on every message. When you send an HTTP request, each layer adds its own header around the data it received from above. The receiver unwraps them in reverse order. This is called encapsulation.

An HTTP request is wrapped in a TCP segment with ports, then an IP packet with addresses, then an Ethernet frame with MAC addresses

Walkthrough: loading a page#

What happens when you type a URL and press Enter? Here is the sequence for a plain HTTP request over TCP.

Timeline between client, DNS resolver and server: DNS lookup, TCP three-way handshake, HTTP request and response, then the four-step TCP close

Here's each step in the diagram, in order:

  1. DNS resolution. The browser asks a DNS resolver to turn the domain name (for example example.com) into an IP address.
  2. TCP handshake. The client opens a connection with three messages:
    • SYN (client): "I'd like to connect."
    • SYN-ACK (server): "Got it, I'm ready too."
    • ACK (client): "Great, we're connected."
  3. HTTP request. The client sends GET / over the connection.
  4. Server processing. The server runs your code, maybe queries a database, and builds a response. This is usually the only part of the latency most engineers think about.
  5. HTTP response. The server sends back a status code, headers and the page.
  6. TCP teardown. The connection is closed with four messages: client FIN, server ACK, server FIN, client ACK.

With HTTPS, a TLS handshake also happens after the TCP handshake and before the HTTP request, adding more round trips.

Why this matters for system design#

Three ideas from the lower layers shape everyday design decisions.

TCP hides a lot of work#

You can usually treat the network as a black box. TCP takes care of reliability, ordering and retransmission for you. You only drop down to UDP when speed matters more than getting every packet, as in live video, voice calls or games.

One request is many packets#

A single layer 7 request turns into many layer 4 and layer 3 packets, plus handshakes. The more of the message a component has to understand, the more work it does. This is why an L4 load balancer (looks only at IP and port) is cheaper per request than an L7 load balancer (parses the HTTP request). See Protocols: Layer 4 and 7.

Connections are expensive, so reuse them#

The TCP handshake (and the TLS handshake on top) costs round trips before any useful data moves. Doing that for every small request is wasteful. Common fixes:

  • Keep-alive: reuse one connection for many requests.
  • Multiplexing (HTTP/2): send many requests over one connection at the same time.
  • Persistent connections (WebSockets, SSE): for real-time updates (SSE is server-sent events, a one-way stream from server to client), keep one connection open instead of reconnecting every second.

Key takeaways#

  • For system design, focus on three layers: network (IP), transport (TCP/UDP) and application (HTTP and friends).
  • Each layer wraps the data from the layer above with its own header.
  • Loading a page means DNS lookup, TCP handshake, (TLS handshake), request, response and teardown, so latency is more than your server's processing time.
  • TCP is the reliable default. UDP trades reliability for lower latency.
  • Opening connections costs round trips, so reuse them with keep-alive, HTTP/2 or persistent connections.
Revision notes · 2 min

Core idea#

Networking is built in layers. Each layer relies on the one below and hides its details from the one above. For system design, focus on three: network (3), transport (4) and application (7).

Key points#

  • Each layer wraps the data from the layer above with its own header. This is encapsulation.
  • The receiver unwraps the headers in reverse order.
  • HTTPS is HTTP running over TLS running over TCP.
  • One layer 7 request becomes many layer 4 and layer 3 packets, plus handshakes.
  • An L4 load balancer (IP and port only) is cheaper per request than an L7 one (parses HTTP).
  • TCP is the reliable default. Use UDP only when speed matters more than every packet.

The three layers that matter#

Layer Name Job Examples
7 Application Defines what messages mean HTTP, DNS, SMTP, FTP
4 Transport Delivers data between two programs TCP (reliable), UDP (fast)
3 Network Addresses and routes packets IP, routers

Loading a web page#

  1. DNS resolution turns the domain into an IP address.
  2. TCP handshake: SYN, SYN-ACK, ACK.
  3. With HTTPS, a TLS handshake adds more round trips here.
  4. The client sends the HTTP request.
  5. The server processes it and sends a response.
  6. TCP teardown: FIN, ACK, FIN, ACK.

Connection reuse#

  • Keep-alive: reuse one connection for many requests.
  • Multiplexing (HTTP/2): send many requests over one connection at the same time.
  • Persistent connections (WebSockets, SSE): keep one connection open for real-time updates.

Pitfalls#

  • Latency is more than server processing time. DNS and handshakes add round trips.
  • Opening a new connection for every small request wastes round trips.

Say it in an interview#

  • "A page load is DNS, TCP handshake, TLS handshake, request, response and teardown."
  • "Handshakes cost round trips, so I reuse connections with keep-alive or HTTP/2."

Found a mistake? Email ask@bigonotes.com