π Load Balancer in System Design β Part 1: Introduction & Fundamentals
π Table of Contents
- What is a Load Balancer?
- Why Use a Load Balancer?
- What Does Load Balancing Actually Do?
- Layer 4 vs Layer 7 Load Balancing
- Real World Examples of Load Balancers
- Conclusion
πΉ What is a Load Balancer?
A load balancer is a system design component that distributes incoming traffic across multiple servers, ensuring no single server is overloaded.
Think of it as a traffic cop standing at the intersection of your application:
- It takes every incoming request (cars).
- Redirects them to the correct server (roads).
- Ensures smooth flow without jams.
π‘ Key Idea: The main purpose of a load balancer is to provide high availability, fault tolerance, and better performance.
π Example:
Imagine an e-commerce app during a sale. Instead of sending all users to one server (which will crash), the load balancer distributes them across multiple servers, ensuring the site stays up.
πΉ Why Use a Load Balancer?
β Increased Availability and Reliability
- By spreading traffic across multiple servers, the system avoids single point of failure.
- If Server A goes down, requests are automatically redirected to Server B or C.
π‘ Real-world Example: Netflix uses global load balancers to reroute traffic if a regional server cluster goes down, so users rarely notice outages.
β Improved Performance
- Prevents any single server from becoming overloaded.
- Ensures fast response times by spreading requests evenly.
π Practical Use: Banking systems route requests like "Check Balance" and "Fund Transfer" across different app servers, reducing delays during peak hours (e.g., salary days).
β Scalability
- As demand grows, you can add new servers to the pool.
- Load balancers automatically start sending traffic to them without downtime.
π Example: During Black Friday, Amazon temporarily adds new servers to handle traffic spikes, balanced automatically by AWS Elastic Load Balancers.
β Maintenance
- Servers can be updated, patched, or restarted without downtime.
- Load balancers reroute traffic to healthy servers while maintenance happens.
π‘ Use Case: Software companies roll out updates to one server at a time, keeping the system online throughout.
πΉ What Does Load Balancing Actually Do?
A load balancer performs 3 key jobs:
- Distributes Requests Evenly
- Prevents overloading any single server.
- Detects Failures
- Monitors servers using health checks (ping, HTTP status).
- Redirects traffic away from failed servers.
- Optimizes User Experience
- Directs requests to the least busy or fastest server.
π Simple Example Flow:
User β Load Balancer β {Server A, Server B, Server C}
If Server A is overloaded:
Next request β Server B (because it's free)
This makes the system resilient, fast, and highly available.
πΉ Layer 4 vs. Layer 7 Load Balancing
Load balancers operate at different OSI layers:
β‘ Layer 4 (Transport Layer)
- Works with TCP/UDP connections.
- Routes requests based on IP + Port.
- Faster but less flexible.
- Canβt inspect HTTP headers or payload.
π Example: A gaming server balancing raw TCP connections between players.
π Layer 7 (Application Layer)
- Works at application level (HTTP/HTTPS, gRPC, WebSockets).
-
Can make routing decisions based on:
- HTTP headers
- Cookies
- Request paths (
/images
vs/api
)
More flexible but slightly slower.
π Example:
-
/videos/*
requests β Video server cluster. -
/api/*
requests β API server cluster.
π‘ Real-World Use: YouTube uses Layer 7 load balancers to route video streaming requests vs. API calls differently.
πΉ Real World Examples of Load Balancers
Letβs see how major companies use them:
- Amazon (E-commerce)
- Uses AWS Elastic Load Balancer to distribute millions of checkout and search requests.
- Ensures scaling during festive sales.
- Netflix (Streaming)
- Uses global load balancing + regional failover.
- If EU servers fail, traffic reroutes to US clusters.
- Banking Apps
- Internal load balancers distribute traffic across multiple app servers.
- Transactions are routed to the least loaded server for speed.
- Gaming Servers
- Online multiplayer games (e.g., PUBG, Fortnite) rely on load balancers to match players with the nearest, least-lag server.
π Diagram Reference:
(You could add a simple diagram like below when publishing)
[ Users ]
β
[ Load Balancer ]
β β β
[ Server A | Server B | Server C ]
πΉ Conclusion
In this part, we covered the fundamentals of load balancing:
- What a load balancer is and why it matters.
- How it improves availability, reliability, scalability, and performance.
- Layer 4 vs. Layer 7 differences.
- Real-world examples from Amazon, Netflix, banks, and gaming.
π In Part 2, weβll dive into the Types of Load Balancers (Hardware, Software, Cloud-based), with deeper analysis of their advantages, challenges, and best-fit use cases.
More Details:
Get all articles related to system design
Hastag: SystemDesignWithZeeshanAli
Git: https://github.com/ZeeshanAli-0704/SystemDesignWithZeeshanAli
Top comments (0)