System Design · Concept Library · Free article
Network Layers: The OSI Model and L4 vs L7
Networks are built in layers so each one solves a single problem and hides it from the layers above. Engineers mostly work with three of them, and the line between layer 4 and layer 7 decides what your load balancers, proxies and gateways can see.
The internet is built in layers, each solving one problem and trusting the layer below for the rest. You really only need three: IP (Layer 3) gets data to the right machine, TCP/UDP (Layer 4) gets it to the right program and adds reliability, and HTTP (Layer 7) carries the actual request. The payoff is one distinction worth real interview points: a Layer 4 router decides without opening your message; a Layer 7 router reads inside it.
Solve each problem once
Getting a message across the internet involves a stack of separate problems: which machine, which program on it, is the data complete, is it private, what does the message actually say. Trying to solve all of that at once would be unmanageable.
So the internet splits the work into layers. Each layer handles one job and hands the rest down to the layer beneath it. When you write app code you live at the top and simply trust everything below — the same way you open a file without thinking about magnetic platters or flash cells.
Encapsulation — the envelope inside an envelope
Layers work by wrapping. Your actual data goes inside an HTTP message, which goes inside a TCP envelope, which goes inside an IP envelope. Each layer only reads its own envelope and leaves the rest sealed. Click through them:
The interactive version of this example is available when JavaScript loads.
The three layers you actually use
The classic textbook model (called OSI) has seven layers, but in practice three carry almost every system-design conversation. Do not memorise the other four — know these cold:
| Layer | Protocol | Its one job |
|---|---|---|
| Layer 3 · Network | IP | Get the data to the right machine (addressing and routing). |
| Layer 4 · Transport | TCP / UDP | Get it to the right program, and (for TCP) make it reliable and ordered. |
| Layer 7 · Application | HTTP, and friends | Carry the actual request — the meaning your app cares about. |
L4 vs L7, where it actually matters
Here is the distinction that earns points. When you put a device in front of your servers to spread traffic (a load balancer) or to sit between client and server (a proxy), it can work at one of two layers — and the choice changes what it can do.
| Layer 4 (transport) | Layer 7 (application) | |
|---|---|---|
| Looks at | Address + port (the outer envelope) | The HTTP request inside (path, headers) |
| Can route by content? | No | Yes — e.g. send /api to one pool, /images to another |
| Speed / cost | Faster, lighter | More work — it opens the message |
| Good for | Raw throughput, long-lived connections | Smart routing, most normal web traffic |
Rapid-fire cheat-sheet
- Why layers at all?
- Each layer solves one problem and can be changed without rewriting the others.
- The three layers that matter?
- L3 IP (right machine), L4 TCP/UDP (right program + reliability), L7 HTTP (the actual request).
- What is encapsulation?
- Wrapping: data inside HTTP inside TCP inside IP; each layer reads only its own envelope.
- L4 vs L7 load balancer?
- L4 routes on address and port without opening the message; L7 reads the HTTP request and can route on path or headers.
- When pick L4 over L7?
- When you want raw speed or long-lived connections and do not need to route on request content.
The takeaway
By GOAT Engineer. Back to Concept Library. Privacy Policy · Contact.