OSI Model
The OSI model helps you understand where different technologies operate (TCP at Layer 4, HTTP at Layer 7, load balancers at Layer 4 or 7).
The OSI (Open Systems Interconnection) model is a conceptual framework that divides network communication into 7 layers: Physical, Data Link, Network, Transport, Session, Presentation, and Application. Each layer handles a specific aspect of network communication and communicates with the layers above and below it.
Why This Matters
The OSI model helps you understand where different technologies operate (TCP at Layer 4, HTTP at Layer 7, load balancers at Layer 4 or 7). In system design, knowing which layer a problem occurs at helps you choose the right solution.
The Building Blocks
- Layer 7 (Application): HTTP, HTTPS, WebSocket, DNS — what most system design focuses on.
- Layer 4 (Transport): TCP (reliable, ordered) vs UDP (fast, unordered) — affects your protocol choice.
- Layer 3 (Network): IP addressing, routing — determines how data traverses the internet.
- Layer 4 vs Layer 7 load balancers: L4 balancers route by IP/port (faster, stateless). L7 balancers can route by URL, cookie, or header (smarter, more flexible).
- Encapsulation: Each layer wraps data with its own header. A single HTTP request becomes an HTTP header + TCP header + IP header + Ethernet frame.
Under the Hood
When you send an HTTP request, it travels down the OSI stack on your machine (Application → Transport → Network → Data Link → Physical), across the network, and back up the stack on the server. Each layer adds/removes its own header. Understanding this helps you debug networking issues and choose the right tools.
How Companies Actually Do This
AWS ELB offers both Application Load Balancer (Layer 7) and Network Load Balancer (Layer 4). ALB can route based on URL path; NLB routes based on IP.
Cloudflare operates at Layer 7 for DDoS protection, inspecting HTTP headers to distinguish legitimate traffic from attacks.
WireGuard VPN operates at Layer 3, encapsulating IP packets inside encrypted tunnels.
Common Pitfalls
- Confusing TCP/IP layers with OSI layers — the TCP/IP model has only 4 layers
- Not knowing where common protocols sit in the stack
Interview Questions Worth Practicing
- What are the 7 layers of the OSI model?
- What is the difference between Layer 4 and Layer 7 load balancing?
- At which OSI layer does TCP operate? HTTP?
The Tradeoffs
- Layer 4 vs Layer 7 LB: L4 is faster and handles more connections; L7 is smarter and can do content-based routing.
- TCP vs UDP: TCP guarantees delivery but adds latency; UDP is faster but unreliable.
Related Topics
The Real-World Incident That Made This Famous
Understanding Osi Model became critical after multiple high-profile production incidents at major tech companies. When systems handle millions of users, even small misunderstandings about Osi Model can lead to cascading failures that cost millions in lost revenue and erode user trust. Companies like Netflix, Google, Amazon, and Meta have all invested heavily in mastering Osi Model because they learned the hard way that ignoring it leads to outages.
The key lesson from these incidents: Osi Model is not just a theoretical concept — it is a practical skill that separates engineers who build resilient systems from those who build fragile ones.
How Senior Engineers Think About This
Senior engineers approach Osi Model differently from textbook definitions. Instead of memorizing rules, they build mental models. They ask: "What problem does Osi Model solve? When does it fail? What are the alternatives?" This problem-first thinking leads to better design decisions because every system has unique constraints.
When evaluating Osi Model in a system design context, experienced engineers consider the failure modes first. What happens when this component goes down? How does the system degrade? Is the degradation graceful or catastrophic? These questions reveal more about your understanding than any textbook definition.
Common Interview Mistakes
Mistake 1: Giving a textbook definition without context. Interviewers want to see you connect Osi Model to real systems and real problems.
Mistake 2: Not discussing trade-offs. Every design decision involving Osi Model has trade-offs. Discuss what you gain and what you give up.
Mistake 3: Overcomplicating the solution. Start with the simplest approach to Osi Model that meets the requirements, then add complexity only when justified.
Production Checklist
- Define clear metrics for measuring the effectiveness of your Osi Model implementation
- Set up monitoring and alerting that specifically tracks Osi Model-related failures
- Document your Osi Model design decisions in Architecture Decision Records (ADRs)
- Test failure scenarios related to Osi Model in staging before production deployment
- Review and update your Osi Model implementation quarterly as system requirements evolve
- Train new team members on the specific Osi Model patterns used in your system
Read the original source | Content from System-Design-Overview
Practical Implementation for .NET Developers
In a .NET application, you would typically implement this pattern using the following approach:
ASP.NET Core setup: Create a service class that encapsulates the logic, register it with dependency injection, and inject it into your controllers or minimal API endpoints. The built-in DI container handles lifecycle management.
Entity Framework Core: For database interactions, EF Core provides the ORM layer. Use migrations for schema management and raw SQL for performance-critical queries. Consider Dapper for read-heavy paths where EF Core's overhead matters.
Azure integration: If deploying to Azure, leverage managed services — Azure Cache for Redis, Azure SQL, Azure Service Bus, Azure Cosmos DB. These eliminate operational overhead and provide built-in monitoring through Application Insights.
Testing: Use xUnit with Testcontainers for integration tests that spin up real databases in Docker. Mock external dependencies with NSubstitute. The WebApplicationFactory class lets you test your entire HTTP pipeline in-process.
Monitoring: Add Application Insights telemetry to track request latency, dependency calls, and custom metrics. Use structured logging with Serilog to make production debugging possible:
Log.Information("Processing order {OrderId} for {CustomerId}", orderId, customerId);
This gives you searchable, structured logs in Azure Monitor or Seq.