SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
  • OSI Model
  • IP Address
  • TCP vs UDP
  • HTTP / HTTPS
  • DNS
  • Proxy vs Reverse Proxy
  • Checksums
  • HTTP/1.1 vs HTTP/2 vs HTTP/3
  • Cookies and CORS
  • Subnets, CIDR and NAT
  • Firewalls and VPN
  • Ports and Sockets
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Foundations/Networking

OSI Model

Seven layers that explain how a message travels from your app to another computer.

⏱ 14 min readBeginnerMust KnowHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

The OSI model splits network communication into 7 layers. Each layer has one job and talks only to the layer above and below it.

  • From top to bottom: 7 Application, 6 Presentation, 5 Session, 4 Transport, 3 Network, 2 Data Link, 1 Physical.
  • When you send data, it goes down the layers. Each layer adds its own header. The receiver goes up, and each layer removes its header.
  • Memory trick (top to bottom): All People Seem To Need Data Processing.

02Concept: What is it?

OSI stands for Open Systems Interconnection. It is a reference model: a map that helps us talk about and fix network problems. Real networks use the simpler TCP/IP stack (4 or 5 layers), but OSI is the common language for engineers.

The 7 layers
7ApplicationHTTP, DNS, SMTP
6PresentationTLS, JSON, JPEG
5SessionOpen, keep, close a chat
4TransportTCP, UDP (ports)
3NetworkIP, routers
2Data LinkEthernet, Wi-Fi (MAC)
1PhysicalCables, radio, fibre
Layers 5, 6 and 7 are usually grouped as 'the application' in TCP/IP. Layers 1 and 2 are grouped as 'network access'.
🧠Key ideas

Layering: each layer does one job and hides the details from others.

Encapsulation: going down, each layer wraps the data with its own header (like putting a letter in an envelope, then in a bigger envelope).

De-encapsulation: going up, each layer opens its own envelope.

Names of the data at each layer (PDU)

LayerNameData unit (PDU)Address / key idea
7 ApplicationApplicationDataURLs, HTTP methods
6 PresentationPresentationDataEncoding, encryption, compression
5 SessionSessionDataSession set-up and tear-down
4 TransportTransportSegment (TCP) or Datagram (UDP)Port numbers
3 NetworkNetworkPacketIP addresses
2 Data LinkData LinkFrameMAC addresses
1 PhysicalPhysicalBitsSignals

03Real-Life Example

🍵Sending a parcel by post
You write a letter (the data). You put it in an envelope and write the address (IP). The post office puts it in a bag for the local van (frame). The van drives on roads (physical). At the other end, each step is undone in reverse until your friend reads the letter.
Posting a letter
OSI layer
Writing the message
7 Application (what to say)
Translating or sealing it
6 Presentation (encode, encrypt)
Agreeing to start and end a chat
5 Session
Numbering the pages, checking they all arrive
4 Transport (TCP)
Writing the full city address on the envelope
3 Network (IP)
Handing it to the next local van driver
2 Data Link (MAC)
The roads and the van
1 Physical
Going down, then up
Sender
Data
↓+ TCP header
Segment
↓+ IP header
Packet
↓+ MAC header
Frame → Bits
→↓over the wire
Receiver
Data
↑− TCP header
Segment
↑− IP header
Packet
↑− MAC header
Frame ← Bits
The sender adds a header at each layer. The receiver removes them in reverse order.

04Why Do We Need It?

🧩Break a big problem into small ones
Each layer is simple and does one job.
🔍Find faults faster
"Is it the cable (1), the IP (3), or the app (7)?" Check layer by layer.
🔌Swap parts easily
Change Wi-Fi to Ethernet and the web app does not care.
🤝Common language
Everyone knows what a layer 4 or layer 7 load balancer means.
🌐Different vendors work together
Standard layers let different products connect.
🎤Interviews
Very common question. It also appears in load balancer and security topics.
The OSI model gives us a map, so we always know where in the network a problem lives.

05Where Do We Use It?

🛠️Troubleshooting
No Wi-Fi? Check layer 1 and 2. Can ping but no website? Check higher layers.
⚖️Load balancers
A layer 4 load balancer uses IP and port. A layer 7 one reads the URL and headers.
🔥Firewalls
Packet filters work at layers 3 and 4. Web application firewalls work at layer 7.
🔐Security
TLS encrypts at (about) layer 6. Attacks are grouped by layer.
🧠Learning
A shared way to teach and discuss networks.
📡Network devices
Hub and cable (1), switch (2), router (3).

06Types / Parts / How It Works

Each layer in simple words

#LayerJobExamples
7ApplicationWhat the user's program uses to talk on the networkHTTP, HTTPS, FTP, SMTP, DNS
6PresentationTranslate, encrypt and compress dataTLS/SSL, JPEG, JSON, ASCII
5SessionStart, keep and end a conversationSessions, RPC, NetBIOS
4TransportEnd-to-end delivery, split into segments, ports, reliabilityTCP, UDP
3NetworkChoose the path between networks using IP addressesIP, ICMP, routers
2Data LinkMove frames between devices on the same network using MAC addressesEthernet, Wi-Fi, switches
1PhysicalSend raw bits as electricity, light or radioCables, fibre, hubs, radio

OSI vs TCP/IP

Two models, side by side
OSI (7)
7ApplicationHTTP, DNS, SMTP
6PresentationTLS, JSON, JPEG
5SessionOpen, keep, close a chat
4TransportTCP, UDP (ports)
3NetworkIP, routers
2Data LinkEthernet, Wi-Fi (MAC)
1PhysicalCables, radio, fibre
TCP/IP (4)
ApplicationOSI 5, 6, 7
TransportOSI 4
InternetOSI 3
Network access (Link)OSI 1, 2
TCP/IP is what the internet really uses. OSI is the teaching map.

A web request through the layers

  1. 1
    7: Your browser makes an HTTP GET request
  2. 2
    6: The data is encrypted with TLS
  3. 3
    5: A session to the server is kept
  4. 4
    4: TCP splits it into segments and adds port 443
  5. 5
    3: IP adds your address and the server address
  6. 6
    2: Ethernet or Wi-Fi adds the next device's MAC address
  7. 7
    1: Bits go out as electricity, light or radio
VisualizerFollow a message through the 7 layersStep down as the sender, then up as the receiver. Click a layer to read about it.
Whose computer?
The message right now (0 headers)
Hello 👋 (data)
Layer 7: Application (Data)
The app talks to the network here.
Examples: HTTP, DNS, SMTP. On the way down it adds: HTTP request.
Tip: click any layer to read about it.

07How to Use It / Steps / Implementation

Using OSI to fix a problem (bottom up)

  1. 1
    Layer 1: Is it plugged in?
    Cable, power, Wi-Fi signal.
  2. 2
    Layer 2: Is the local link up?
    Switch port, MAC, Wi-Fi connected to the router.
  3. 3
    Layer 3: Does it have an IP and a route?
    Use ping to test. Check the IP address and gateway.
  4. 4
    Layer 4: Is the port open?
    Is TCP connecting? Is a firewall blocking the port?
  5. 5
    Layers 5 to 7: Is the app right?
    Check TLS certificates, HTTP status codes and app logs.

Choosing a load balancer by layer

Layer 4 load balancerLayer 7 load balancer
Looks atIP address and portURL, headers, cookies
SpeedVery fast, simpleSlower, smarter
Can route /images to a special server?NoYes
Can end TLS?Not usuallyYes
💡Handy commands
ping tests layer 3. traceroute shows hops (layer 3). curl tests layer 7.

08Key Terms to Know

TermMeaning in easy words
LayerOne level of the model. It does one job.
ProtocolA set of rules for talking at one layer, like HTTP or TCP.
EncapsulationWrapping data with a header at each layer on the way down.
De-encapsulationRemoving those headers on the way up.
PDUProtocol data unit: the name of the data at each layer (data, segment, packet, frame, bits).
HeaderExtra control information added at the front of the data.
MAC addressA hardware address of a network card. Used on the local network (layer 2).
IP addressA logical address used to route between networks (layer 3).
PortA number that picks the app on a machine (layer 4).
SwitchLayer 2 device that forwards frames by MAC address.
RouterLayer 3 device that forwards packets by IP address.
TCP/IPThe real protocol suite of the internet. It has 4 layers.

09Pros, Cons and Trade-offs

✅ Pros
  • Easy to learn and teach
  • Helps find where a fault is
  • Layers can change without breaking others
  • A shared language across companies
⚠️ Cons
  • It is a model, not exactly how the internet works
  • Layers 5 and 6 are often blurry in practice
  • Extra headers add a small cost
  • Some features (like TLS) do not fit neatly in one layer
📝Note
OSI is a teaching and thinking tool. The internet itself runs on TCP/IP.

10Common Problems and Mistakes

Common mistakes

  1. Mixing the order. Layer 1 is the bottom (physical). Layer 7 is the top (application).
  2. Thinking HTTP is layer 4. HTTP is layer 7. TCP and UDP are layer 4.
  3. Confusing a switch with a router. Switch = layer 2 (MAC). Router = layer 3 (IP).
  4. Believing the internet uses 7 layers. It uses TCP/IP. OSI is the reference.
  5. Calling the application (browser) layer 7. Layer 7 is the protocol the app uses, not the app itself.
  6. Debugging only at layer 7. Many problems are lower down.

11Real-World Examples

⚖️AWS Network vs Application Load Balancer
The Network Load Balancer works at layer 4. The Application Load Balancer works at layer 7.
🔥Firewalls
Network firewalls filter by IP and port. Web application firewalls read HTTP.
🌐HTTPS on websites
HTTP (7) runs inside TLS, which runs on TCP (4), on IP (3).
🏠Your home router
It does layer 3 routing, and often layer 2 switching and Wi-Fi too.

12Related Topics to Read Next

IP Address→

The layer 3 address.

TCP vs UDP→

The two main layer 4 protocols.

HTTP / HTTPS→

The most common layer 7 protocol.

DNS→

A layer 7 protocol that turns names into IP addresses.

What are Load Balancers?→

They work at layer 4 or layer 7.

Proxy vs Reverse Proxy→

Usually work at layer 7.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔7 layers (top to bottom): Application, Presentation, Session, Transport, Network, Data Link, Physical.
  • ✔Memory trick: All People Seem To Need Data Processing.
  • ✔PDU: data, segment, packet, frame, bits.
  • ✔Addresses: MAC (layer 2), IP (layer 3), port (layer 4).
  • ✔Devices: switch (2), router (3).
  • ✔Protocols: HTTP and DNS (7), TCP and UDP (4), IP (3), Ethernet (2).
  • ✔Down = encapsulate. Up = de-encapsulate.
  • ✔The internet uses TCP/IP. OSI is the reference map.
← Previous
Back Pressure
Next →
IP Address