How do Load balancer work?
Published:
How Do Different Kinds of load balancer work, and How do they route requests?
Introduction
There are different kinds of Load balancers, and they work on different layers of networking. Before, going through the Load Balancer, I am going to introduce the network layers.
OSI Model: The Seven Layers of Networking
The OSI (Open Systems Interconnection) model is a conceptual framework used to understand and implement networking protocols in seven distinct layers. Each layer serves a specific function and interacts with the layers directly above and below it. Here is an overview of each layer from the topmost application layer to the bottommost physical layer.
1. Application Layer
- Layer Number: 7
- Function: This layer provides network services directly to end-user applications. It is responsible for ensuring that communication partners are identified, quality of service is identified, user authentication and privacy are considered, and any constraints on data syntax are identified.
- Examples: HTTP, FTP, SMTP, POP3, IMAP
2. Presentation Layer
- Layer Number: 6
- Function: The presentation layer translates data between the application layer and the network format. It is responsible for data encryption, compression, and translation services. It ensures that the data is in a readable format for the application layer.
- Examples: SSL/TLS, JPEG, MPEG, GIF
3. Session Layer
- Layer Number: 5
- Function: The session layer manages and controls the connections between computers. It establishes, maintains, and terminates connections between applications. It is also responsible for session checkpointing and recovery.
- Examples: NetBIOS, RPC, SQL
4. Transport Layer
- Layer Number: 4
- Function: The transport layer provides transparent transfer of data between end systems and is responsible for end-to-end error recovery and flow control. It ensures complete data transfer.
- Examples: TCP, UDP
5. Network Layer
- Layer Number: 3
- Function: The network layer handles the routing of data, logical addressing, and packet forwarding. It determines the best physical path for data to reach its destination.
- Examples: IP, ICMP, IGMP
6. Data Link Layer
- Layer Number: 2
- Function: The data link layer is responsible for node-to-node data transfer and handles error detection and correction from the physical layer. It also manages MAC addressing.
- Examples: Ethernet, PPP, HDLC
7. Physical Layer
- Layer Number: 1
- Function: The physical layer is concerned with the transmission and reception of the unstructured raw bit stream over a physical medium. It deals with the electrical and physical specifications of the devices.
- Examples: USB, Bluetooth, DSL, 802.11 (Wi-Fi)
Comparison of Load Balancers: ALB vs. NLB vs. GLB vs. ELB
Load balancers distribute incoming traffic across multiple servers or resources to optimize performance, enhance reliability, and ensure high availability. The 3 prominent ones stand out: ALB, NLB, and ELB. Let’s dive into the nuances of each to understand their strengths and ideal use cases.
ALB (Application Load Balancer)
Overview: ALB operates at Layer 7 of the OSI model, offering advanced routing capabilities and content-based routing. It is tailored for modern applications running in containers or microservices architectures.
Key Features:
- Path-Based Routing: ALB can route traffic based on the URL path of the incoming request, allowing for efficient routing to different backend services.
- Host-Based Routing: Traffic can be directed to different backend servers based on the host header of the incoming request.
- Support for WebSocket: ALB seamlessly handles WebSocket traffic, making it suitable for real-time applications.
Ideal Use Cases: ALB works in scenarios where flexible routing and support for modern application architectures are required, such as microservices-based applications and containerized environments.
NLB (Network Load Balancer)
Overview: NLB operates at Layer 4 of the OSI model, providing high-performance, low-latency load balancing for TCP and UDP traffic. It is designed for extreme performance and scalability.
Key Features:
- Ultra-Low Latency: NLB offers sub-millisecond latency and can handle millions of requests per second, making it ideal for latency-sensitive applications.
- Static IP Addresses: Each NLB instance is associated with a static IP address, simplifying DNS management and providing a stable endpoint for clients.
Ideal Use Cases: NLB excels in scenarios requiring high throughput, low latency, and scalability, such as high-traffic websites, gaming applications, and IoT platforms.
ELB (Elastic Load Balancer)
Overview: ELB is a legacy load balancing service provided by AWS, encompassing both Classic Load Balancer and Application Load Balancer (ALB). While still widely used, its functionality is gradually being superseded by ALB and NLB.
Key Features:
- Auto Scaling Integration: ELB seamlessly integrates with AWS Auto Scaling, allowing for automatic adjustment of load balancer capacity based on traffic patterns.
- Integrated Monitoring: ELB provides comprehensive monitoring and logging capabilities, facilitating performance analysis and troubleshooting.
Ideal Use Cases: ELB remains an option for legacy applications and workloads running on AWS, although newer applications may benefit from the enhanced features and performance of ALB or NLB.
Conclusion
In summary, the choice of load balancer depends on various factors such as application architecture, performance requirements, scalability needs, and geographic distribution. ALB, NLB, GLB, and ELB each offer unique features and capabilities tailored to different use cases. By understanding their strengths and limitations, organizations can select the most suitable load balancing solution to optimize the performance, reliability, and availability of their applications.