0
0
HLDsystem_design~12 mins

Layer 4 vs Layer 7 load balancing in HLD - Architecture Patterns Compared

Choose your learning style9 modes available
System Overview - Layer 4 vs Layer 7 load balancing

This system demonstrates the difference between Layer 4 and Layer 7 load balancing. It shows how incoming user requests are distributed to backend services either by network-level information (Layer 4) or by application-level data (Layer 7). Key requirements include efficient traffic distribution, scalability, and the ability to handle different routing rules.

Architecture Diagram
User
  |
  v
+-----------------+
|  Load Balancer  |
|  (Layer 4 or 7) |
+-----------------+
  |           |
  v           v
Service A   Service B
  |           |
  v           v
Database    Database
Components
User
client
Sends requests to the system
Load Balancer
load_balancer
Distributes incoming requests to backend services based on Layer 4 or Layer 7 rules
Service A
service
Handles requests routed by the load balancer
Service B
service
Handles requests routed by the load balancer
Database
database
Stores persistent data for services
Request Flow - 6 Hops
UserLoad Balancer
Load BalancerService A or Service B
Service A or Service BDatabase
DatabaseService A or Service B
Service A or Service BLoad Balancer
Load BalancerUser
Failure Scenario
Component Fails:Load Balancer
Impact:All incoming user requests fail to be routed, causing complete service outage
Mitigation:Use multiple load balancers with failover or clustering to avoid single point of failure
Architecture Quiz - 3 Questions
Test your understanding
Which layer does a Layer 4 load balancer operate on?
ATransport layer (IP and TCP/UDP ports)
BApplication layer (HTTP headers and URLs)
CPhysical layer (cables and signals)
DSession layer (manages sessions)
Design Principle
This architecture shows how load balancers at different layers affect routing decisions and system flexibility. Layer 4 load balancers are faster but less flexible, while Layer 7 load balancers enable smarter routing based on application data but add processing overhead. Redundancy in load balancers is critical to avoid single points of failure.