System design2 min
The OSI Model & TCP/IP
To design robust distributed systems, you must understand how computers communicate over a network. Two conceptual models explain this: the OSI Model (theoretical) and the TCP/IP Model (practical).
The OSI Model (Open Systems Interconnection)
The OSI model is a 7-layer theoretical framework used to understand and standardize network communication. Data flows down the layers on the sending device and up the layers on the receiving device.
- Physical Layer (L1): Deals with the physical transmission of raw bits (0s and 1s) over cables, fiber optics, or radio waves.
- Data Link Layer (L2): Organizes bits into frames. Handles node-to-node delivery using MAC addresses. Switches operate here.
- Network Layer (L3): Organizes frames into packets. Handles end-to-end delivery using IP addresses and routing. Routers operate here.
- Transport Layer (L4): Organizes packets into segments. Ensures reliable or unreliable data transfer using ports (TCP/UDP).
- Session Layer (L5): Establishes, maintains, and terminates communication sessions between applications.
- Presentation Layer (L6): Translates data into a standard format. Handles encryption (TLS/SSL) and compression.
- Application Layer (L7): The interface for network applications (e.g., HTTP, FTP, SMTP). This is what you build your web apps on!
The TCP/IP Model
The TCP/IP model is a more practical, 4-layer model that actually reflects how the internet works today. It collapses some of the OSI layers:
- Network Access Layer: Combines OSI L1 and L2.
- Internet Layer: Equivalent to OSI L3 (IP protocol).
- Transport Layer: Equivalent to OSI L4 (TCP/UDP).
- Application Layer: Combines OSI L5, L6, and L7.
Why Does This Matter in System Design?
Understanding layers is crucial when making architectural decisions:
- Load Balancing: Do you need an L4 load balancer (fast, routes based on IP/Port) or an L7 load balancer (slower, can route based on HTTP headers or URL paths)?
- Troubleshooting: If a service is down, is it a DNS issue (L7), a blocked port (L4), a routing issue (L3), or a physical cut cable (L1)?
- Security: Do you need a Web Application Firewall (WAF) at L7, or just a Network Firewall at L3/L4?