When designing large-scale distributed systems, your microservices, databases, and caches must constantly communicate over networks. To build secure, fast, and scalable communication channels, you need to understand how data travels across the wire. In High-Level Design (HLD), the universal framework used to understand network communication is the OSI Model (Open Systems Interconnection Model).
The OSI Model divides network communication into 7 distinct, logical layers. Each layer handles a specific part of the data transmission process and serves the layer directly above it.
Key ideas:
The OSI Model abstracts complex physical networking hardware into predictable software boundaries.
Data travels down the 7 layers on the sender's side (encapsulation) and up the 7 layers on the receiver's side (decapsulation).
As an application architect, your focus will primarily live at the highest layers (Layers 4 and 7), where protocols like HTTP, gRPC, and TCP operate.
The 7 Layers of the OSI Model
Let's break down the 7 layers from top to bottom, starting from where the user interacts with the software down to the physical hardware cables.
Layer 7: The Application Layer
This is the layer that interacts directly with your software application. It receives data from the user and displays incoming data to the user.
Protocols: HTTP, HTTPS, FTP, SMTP (Email), DNS, gRPC.
HLD Relevance: This is where your API Gateways and microservices live. When you design a REST API or an e-commerce checkout route, you are working entirely inside Layer 7.
Layer 6: The Presentation Layer
This layer acts as the system's translator. It ensures that data is formatted, structured, and presented in a syntax that the destination application can actually read and understand.
Key Tasks: Data Encryption/Decryption (SSL/TLS), Data Compression, and Character Encoding (converting string text to JSON or XML formats).
HLD Relevance: When you secure an API route using HTTPS or compress a payload using GZIP to lower bandwidth costs, Layer 6 handles the heavy lifting.
Layer 5: The Session Layer
The Session Layer is responsible for opening, managing, and closing communication channels between two separate devices. It tracks how long a connection stays open and cleans it up when communication ends.
Key Tasks: Session checkpoints, authentication verification, and handling sudden re-connections if a wire drops briefly.
HLD Relevance: Managing stateful WebSocket connections for a live chat application occurs at this tier.
Layer 4: The Transport Layer
The Transport Layer handles host-to-host data transfer. It takes the massive data payload from the upper layers, breaks it down into smaller, manageable chunks called segments, and ensures they reach the other side reliably.
Protocols: TCP (Transmission Control Protocol) and UDP (User Datagram Protocol).
HLD Relevance: Highly critical for system design interviews. You must choose whether your service-to-service links need the strict, error-checked reliability of TCP (good for banking data) or the raw speed of UDP (good for live video streaming).
Layer 3: The Network Layer
The Network Layer is responsible for moving data across completely different networks. It takes your data segments, wraps them into packets, and figures out the best physical routing path to send them on.
Key Components: IP Addresses, Routers, and ICMP.
HLD Relevance: This layer determines how data hops between different global cloud regions or separate private subnets inside an AWS Virtual Private Cloud (VPC).
Layer 2: The Data Link Layer
While the Network Layer handles routing across the global internet, the Data Link Layer manages data transfer between two devices connected to the exact same local network. It takes packets and breaks them into smaller units called frames.
Key Components: MAC Addresses, Network Switches, and Ethernet protocols.
HLD Relevance: This layer dictates how servers sitting inside the same physical server rack communicate with each other instantaneously via local switches.
Layer 1: The Physical Layer
The lowest tier of the OSI model. This layer covers the actual physical hardware equipment involved in communication. It translates data frames into a raw stream of unstructured electrical, radio, or optical signals (bits of 0s and 1s).
Key Components: Fiber optic cables, copper wires, Wi-Fi radio frequencies, hubs, and connectors.
HLD Relevance: This is where physical latency boundaries occur, such as the speed limit of light passing through under-sea internet cables.
How Data Travels: Encapsulation vs. Decapsulation
When Service A sends a message to Service B, the data undergoes a process of wrapping and unwrapping as it traverses the OSI stack.
1. Encapsulation (On the Sender's Machine)
Your microservice generates a raw message (e.g., a JSON string).
As the message travels down from Layer 7 to Layer 1, each layer slaps its own metadata "header" onto the package.
The Transport layer adds TCP port instructions, the Network layer appends target IP addresses, and the Data Link layer attaches MAC addresses.
By the time it hits Layer 1, it is an encoded stream of 1s and 0s sent out across a cable.
2. Decapsulation (On the Receiver's Machine)
The destination server receives the raw physical bits at Layer 1.
As the data travels up from Layer 1 to Layer 7, each layer strips away its corresponding header, reads the routing instructions, and passes the remaining payload to the layer above it.
Finally, the clean, original JSON message arrives safely at the target microservice at Layer 7.
HLD Focus: Layer 4 vs. Layer 7 Load Balancing
A classic architectural choice driven directly by the OSI model is choosing between Layer 4 Load Balancing and Layer 7 Load Balancing.
Layer 4 Load Balancer: Operates at the Transport Layer. It only inspects basic network data like target IP addresses and TCP ports. It routes traffic blindly without looking at the message content. It is extremely fast, uses low CPU resources, but cannot make smart routing choices.
Layer 7 Load Balancer: Operates at the Application Layer. It terminates the network connection and looks inside the actual message payload (HTTP paths, cookies, and headers). It can route
/videorequests to a video server and/paymentrequests to a payment server. It requires more computing power but provides high flexibility.
Summary
The OSI Model is a 7-layer logical framework that structures how data moves across a distributed network.
Upper layers (5-7) focus on application logic, encryption, and formatting, while lower layers (1-4) manage data delivery, packaging, and physical transport.
Data is progressively wrapped with routing metadata via encapsulation on the way out, and unwrapped via decapsulation on the way in.
Architects use layer boundaries to determine optimization strategies, such as choosing between lightning-fast Layer 4 routing or highly intelligent Layer 7 proxy filtering.