Overview
Curated: · Written: · Reviewed:
OSI & TCP/IP Models
In one line
Each layer is a service contract with a narrow scope. Use the model to decide which contract a symptom violates and which capture proves it. OSI has seven layers, but the deployed stack is TCP/IP: link, internet, transport, application. Reach for it when a request fails somewhere between the application and the wire and you need to pick where to look first.
Key definitions
- Encapsulation: each layer wraps the one above in its own header, and the receiver unwraps in reverse.
- PDU names: frame (link), packet (IP), segment (TCP) or datagram (UDP).
- Best effort: IP gives no guarantee of order, single delivery or arrival.
- Four-tuple: source IP, source port, destination IP, destination port. It identifies a TCP connection, not the listening port alone.
- PMTUD: finding the smallest MTU on a path using ICMP Fragmentation Needed (IPv4, DF set) or Packet Too Big (IPv6).
- ARP / NDP: resolve an IP address to a MAC address on the local link.
Formulas and complexity
Worked example, labelled hypothetical: a 64 KiB window over a 40 ms RTT caps throughput at about 13.1 Mbit/s, whatever the link speed.
How it works
An off-subnet send is handled hop by hop:
- The host ARPs for its default gateway. The frame's destination MAC is the gateway's; the IP destination stays the final host.
- Each router rewrites the link-layer addresses and decrements TTL (Hop Limit in IPv6). IPv4 also recomputes the header checksum.
- IPv6 routers never fragment. The source host owns Path MTU Discovery.
- A TCP byte stream has no message boundaries. Applications must frame their own records.
When to use and when not to
| Need | Choose | Reason |
|---|---|---|
| Every byte, in order | TCP or QUIC | Transport guarantees retransmission and ordering |
| Freshness over completeness | UDP | No retransmission; drop stale data in the application |
| Many streams, no cross-stream stall | QUIC | Per-stream ordering |
| Tunnels, QUIC, VXLAN | Neither layer alone | They span layers; discuss the contracts instead |
Do not use the model to assign performance blame. Loss at layer 2 shows up as retransmissions at layer 4.
Traps interviewers probe
- "TCP preserves messages." It preserves byte order only. Fix: length-prefix records, handle partial reads, and treat uncertain outcomes on retried requests.
- "Blocking ICMP is safer." It breaks PMTUD, and on IPv6 it breaks neighbor discovery. Fix: permit Fragmentation Needed and Packet Too Big, or clamp MSS at the tunnel.
- "DNS resolved, so the service is reachable." A resolved name says nothing about reachability. Fix: RST means nothing is listening (ECONNREFUSED); a timeout means filtered or dropped.
- "A star in traceroute means that hop is down." Many routers rate-limit ICMP Time Exceeded. Fix: check whether later hops answer.
- "Switches and routers forward the same way." Switches forward by MAC within a broadcast domain and keep the frame. Routers forward by prefix, rewrite MACs, and decrement TTL.
Interview tips
Opening: "Layers are contracts. I'd locate the symptom by the contract it violates, then name the capture that proves it."
Expect these follow-ups:
- Where QUIC fits: transport over UDP, with per-stream ordering. Packet loss still stalls every stream that shares the connection's congestion control.
- Why a connection works from one subnet and not another: check subnet mask, gateway, ARP, firewall, and MTU.
- Why a TCP connection succeeds but the application fails: TLS and application semantics sit above the byte stream.
- Which layer a load balancer operates at: it depends on whether it inspects L4 flows or L7 content.
30-second outline:
- Name the layers the symptom touches.
- State the contract that is violated.
- Give the evidence: packet sizes, DF bit, RST or timeout, ARP entry.
- Give the fix and the check that proves it. Name the capture point, because a host capture can miss what the wire carried.
The Overview is now longer than the first draft and sits within the 600-900 word range.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.