Documentation Index
Fetch the complete documentation index at: https://resources.devweekends.com/llms.txt
Use this file to discover all available pages before exploring further.
Module 2: Network Models
To understand how networks function, we use reference models that break down communication into layers. The two most important models are OSI and TCP/IP. Why layers? Consider the postal system analogy. When you mail a letter, you do not think about how the mail truck’s engine works. You write your message (application layer), put it in an envelope with an address (network layer), and hand it to the post office (physical layer). Each layer handles its own job without worrying about the others. Networking layers work the same way — a web developer writing an HTTP request does not need to understand voltage levels on copper wire.2.1 The OSI Model
The Open Systems Interconnection (OSI) model has 7 layers. Think of it as a factory assembly line where each station adds something specific before passing the product to the next station.- Physical Layer (Layer 1): Bits, cables, signals. This is the actual wire, fiber, or radio wave. It only understands 0s and 1s — raw electrical or optical pulses. Analogy: the road itself.
- Data Link Layer (Layer 2): Frames, MAC addresses, switching. Responsible for getting data to the next directly-connected device. MAC addresses are used here — they are like apartment numbers within a building. Analogy: the local mail carrier who delivers within your neighborhood.
- Network Layer (Layer 3): Packets, IP addresses, routing. Handles end-to-end delivery across multiple networks. IP addresses live here. Analogy: the ZIP code that tells the postal system which city to route your letter to.
- Transport Layer (Layer 4): Segments, TCP/UDP, reliability. Ensures data arrives completely and in order (TCP) or fires it quickly without guarantees (UDP). Analogy: TCP is certified mail with tracking; UDP is dropping a postcard in the mailbox and hoping for the best.
- Session Layer (Layer 5): Session management. Establishes, maintains, and terminates connections between applications. In practice, this layer is mostly absorbed into Layer 4 and Layer 7.
- Presentation Layer (Layer 6): Data formatting, encryption, compression. Ensures the data is in a format the application can understand (e.g., SSL/TLS encryption, character encoding). Think of it as translating between languages before the message reaches the recipient.
- Application Layer (Layer 7): User applications (HTTP, SMTP, DNS). This is the layer you interact with directly. When your browser makes a request, it speaks HTTP at this layer.
Practical reality: Layers 5 and 6 are mostly theoretical in modern networking. The TCP/IP model (below) merges them into the Application layer. When someone says “Layer 7 load balancer,” they mean it inspects HTTP content. When they say “Layer 4 load balancer,” it only looks at TCP/UDP ports and IP addresses. You will hear “Layer 3” and “Layer 7” constantly in real-world discussions — Layers 5 and 6 almost never come up.
2.2 The TCP/IP Model
The TCP/IP model is the practical implementation used in the Internet today. While OSI is the “textbook” model, TCP/IP is what actually runs the internet. It condenses the OSI layers into 4 (or 5) layers.- Network Interface (Physical + Data Link) — handles the physical transmission and local delivery
- Internet (Network) — IP addressing and routing across networks
- Transport (Transport) — end-to-end reliability (TCP) or speed (UDP)
- Application (Session + Presentation + Application) — everything the user-facing software does, including HTTP, DNS, SMTP, and TLS encryption
Why two models?
The OSI model was designed by committee (ISO) as an ideal reference before the internet took off. The TCP/IP model was designed by engineers who were actually building the internet. OSI is great for learning and discussing networking concepts. TCP/IP is what you will see in actual protocol headers, packet captures, and documentation. In interviews and real-world discussions, people freely mix terminology from both models — “Layer 7” is OSI terminology, but everyone uses it when talking about TCP/IP networks.2.3 Encapsulation
Data is wrapped with headers (and trailers) as it moves down the layers. Think of it like putting a letter in an envelope, then putting that envelope in a shipping box, then putting that box on a delivery truck. Each layer adds its own “wrapping” with the information it needs.- Application: Data — the raw message, like the text of your letter.
- Transport: Segment (Data + TCP Header) — adds port numbers and sequence numbers, like writing “page 3 of 10” on the letter.
- Internet: Packet (Segment + IP Header) — adds source and destination IP addresses, like writing the sender and recipient addresses on the envelope.
- Link: Frame (Packet + Frame Header + Trailer) — adds MAC addresses and error-checking, like the shipping label and “fragile” sticker on the box.
Next Module
Module 3: Physical & Data Link
Explore the bottom layers of the stack.
Interview Deep-Dive
Why do we have both the OSI model and the TCP/IP model? Which one actually matters in production?
Why do we have both the OSI model and the TCP/IP model? Which one actually matters in production?
Strong Answer:
- The OSI model was designed by the ISO committee as a theoretical reference framework before the internet took off. It has 7 layers and provides a clean separation of concerns for teaching and discussing networking concepts. The TCP/IP model was built by the engineers actually constructing the internet — it is pragmatic, has 4 layers, and maps directly to real protocol implementations.
- In production, the TCP/IP model is what matters. Protocol headers, packet captures in Wireshark, and documentation all reference TCP/IP. However, OSI terminology dominates real-world conversations — everyone says “Layer 7 load balancer” or “Layer 4 firewall,” and those are OSI layer numbers. Nobody says “Application layer load balancer in the TCP/IP model.”
- Layers 5 (Session) and 6 (Presentation) from the OSI model are almost never discussed in practice. They have been absorbed into the Application layer in TCP/IP. When I hear someone reference Layer 5 or 6 in an interview, it often signals textbook knowledge without operational experience.
- The practical value of the layered model is troubleshooting. When something breaks, you work bottom-up: is the cable connected (Layer 1)? Can I ping the gateway (Layer 3)? Is the port open (Layer 4)? Is the application responding (Layer 7)? This systematic approach is the real gift of the model, regardless of which model you reference.
/api/* to one backend pool and /static/* to another, perform SSL termination, inject headers like X-Forwarded-For, and do A/B testing. The trade-off is higher latency and more CPU usage because it parses the entire HTTP request. In practice, you default to L7 for web applications and use L4 for non-HTTP protocols like database connections or game servers.Explain encapsulation. If I capture a packet with Wireshark leaving a web server, what headers will I see and in what order?
Explain encapsulation. If I capture a packet with Wireshark leaving a web server, what headers will I see and in what order?
Strong Answer:
- Encapsulation is the process where each layer of the networking stack wraps the data from the layer above with its own header (and sometimes a trailer). It is like putting a letter in an envelope, then putting that envelope in a shipping box, then loading the box onto a truck.
- In a Wireshark capture of an HTTPS response leaving a web server, I would see from outside to inside: the Ethernet frame header (source and destination MAC addresses, EtherType 0x0800 for IPv4), the IP header (source and destination IP addresses, TTL, protocol field set to 6 for TCP), the TCP header (source port 443, destination port matching the client’s ephemeral port, sequence and acknowledgment numbers, flags), and then the TLS record containing the encrypted application data. Wireshark cannot decrypt the TLS payload unless you provide the session keys.
- At the end of the frame, there is an FCS (Frame Check Sequence) trailer — a CRC checksum for detecting corruption during transmission. If the FCS does not match, the frame is silently dropped at Layer 2 without any notification to the sender. Retransmission, if any, happens at Layer 4 (TCP).
- The critical insight is that each layer only reads its own header. A router examines the IP header for routing decisions but ignores TCP and application data. This is why Layer 4 load balancers are faster than Layer 7 ones — they stop reading earlier.
A junior engineer asks you: 'Why can't we just have one layer that does everything?' How would you explain the value of layered architecture?
A junior engineer asks you: 'Why can't we just have one layer that does everything?' How would you explain the value of layered architecture?
Strong Answer:
- Layered architecture exists for the same reason we have separation of concerns in software engineering: it allows each layer to evolve independently without breaking the others. HTTP does not care whether the underlying transport is TCP, QUIC, or something invented next year. Ethernet does not care whether the packets it carries contain IP, ARP, or IPv6. This independence is what allowed the internet to grow from a research project to a global infrastructure without requiring coordinated rewrites at every level.
- In practice, this means I can switch my application from HTTP/1.1 to HTTP/2 without changing anything about my network infrastructure. I can upgrade from copper to fiber without touching a single application configuration. I can deploy a VPN (which adds an encapsulation layer) without modifying the applications running through it.
- Layering also makes troubleshooting tractable. If I had one monolithic protocol, a failure could be anywhere. With layers, I can systematically isolate: “Layer 1 is fine (link light is on), Layer 3 is fine (I can ping the gateway), Layer 4 is fine (port is open), so the problem must be at Layer 7 (application misconfiguration).” That process saves hours compared to blind guessing.
- The trade-off is overhead. Each layer adds its own headers, which means a 1-byte application message might become a 66-byte frame by the time all headers are added. And sometimes the layer boundaries create artificial constraints — for example, TCP’s head-of-line blocking problem, which HTTP/3 solves by moving to UDP (QUIC) and reimplementing reliability at the application layer.