Load balancing phân phối request qua nhiều server — thuật toán phổ biến bao gồm Round Robin, Least Connections, và IP Hash, mỗi loại phù hợp với use case khác nhau.
- Round Robin: phân phối request lần lượt qua các server — đơn giản nhưng không tính đến load thực tế.
- Weighted Round Robin: server mạnh hơn nhận nhiều request hơn theo tỷ lệ cấu hình.
- Least Connections: gửi đến server có ít active connections nhất — tốt khi request duration không đều nhau.
- Least Response Time: chọn server có response time thấp nhất — cần monitoring liên tục.
- IP Hash: hash IP client để luôn route đến cùng một server (sticky session) — quan trọng khi app có state (session).
- Random: chọn ngẫu nhiên — đơn giản, hoạt động tốt với số lượng server lớn.
Trong thực tế: Nginx/HAProxy/AWS ALB hỗ trợ hầu hết các thuật toán này; Kubernetes dùng iptables/ipvs với round-robin mặc định. Health check là thành phần bắt buộc — LB phải tự động loại server unhealthy khỏi pool.
Load balancing distributes requests across multiple servers — common algorithms include Round Robin, Least Connections, and IP Hash, each suited for different use cases.
- Round Robin: distributes requests sequentially across servers — simple but ignores actual server load.
- Weighted Round Robin: higher-capacity servers receive a proportionally larger share of requests based on configured weights.
- Least Connections: routes to the server with the fewest active connections — effective when request durations vary.
- Least Response Time: selects the server with the lowest response time — requires continuous monitoring.
- IP Hash: hashes the client IP to always route to the same server (sticky session) — important for stateful applications using sessions.
- Random: selects a server at random — simple and works well at scale.
In practice, Nginx/HAProxy/AWS ALB support most of these algorithms; Kubernetes uses iptables/ipvs with round-robin by default. Health checks are mandatory — the load balancer must automatically remove unhealthy servers from the pool.