Load Balancer (ตัวจัดการโหลด) คืออะไร?
Load Balancer เป็นอุปกรณ์หรือซอฟต์แวร์ที่กระจายการร้องขอเครือข่าย (Network Traffic) หรือการเชื่อมต่อแอปพลิเคชันไปยังเซิร์ฟเวอร์หลายเครื่อง (Server Pool/Farm) เพื่อให้ไม่มีเซิร์ฟเวอร์ใดทำงานหนักเกินไป ทำให้ระบบมี ความพร้อมใช้งานสูง (High Availability), ประสิทธิภาพดีขึ้น, และ ขยายได้ (Scalability)
ประเภทหลักของ Load Balancer
| ประเภท | เลเยอร์ (OSI) | การตัดสินใจ | ตัวอย่าง |
|---|---|---|---|
| Layer 4 (L4) / Network Load Balancer (NLB) | Transport (Layer 4) | IP Address, Port, Protocol (TCP/UDP) | AWS NLB, Azure Load Balancer, Google Cloud Network LB, LVS (Linux), HAProxy (TCP mode) |
| Layer 7 (L7) / Application Load Balancer (ALB) | Application (Layer 7) | HTTP Headers, URL Path, Host, Cookies, Query Strings | AWS ALB, NGINX, HAProxy (HTTP mode), F5 BIG-IP, Citrix ADC, Traefik, Envoy |
| Global Server Load Balancing (GSLB) | DNS / Application | Geolocation, Health, Latency, Datacenter | Cloudflare Load Balancing, AWS Route 53, F5 GTM, Akamai |
อัลกอริทึมการกระจายโหลด (Load Balancing Algorithms)
- Round Robin - สลับกันตามลำดับ
- Weighted Round Robin - สลับกันแต่มีน้ำหนักตามความสามารถเซิร์ฟเวอร์
- Least Connections - ส่งไปที่เซิร์ฟเวอร์ที่มี Connection น้อยที่สุด
- Least Response Time - ส่งไปที่ตอบสนองเร็วที่สุด
- IP Hash / Source IP Affinity - ผูก Session ไปเซิร์ฟเวอร์เดียวกัน (Sticky Session)
- Least Bandwidth / Least Packets
Load Balancer และความปลอดภัย (Security)
Load Balancer สมัยใหม่ไม่ได้แค่กระจายโหลด แต่ยังให้คุณสมบัติความปลอดภัยสำคัญ:
- SSL/TLS Termination (Offloading) - ถอดรหัสเข้ารหัสที่ LB ลดภาระ CPU เซิร์ฟเวอร์เบ็กเอนด์
- Web Application Firewall (WAF) Integration - บล็อก OWASP Top 10 (SQLi, XSS, RCE) ก่อนถึงแอป
- DDoS Protection - ดูดซับ/กรองโจมตี volumetric และ application-layer (เช่น AWS Shield, Cloudflare)
- Access Control / Rate Limiting / IP Reputation
- Authentication Offloading (OAuth/OIDC/SAML)
- Certificate Management - จัดการใบรับรอง SSL 集中
Load Balancer แบบ Hardware vs Software vs Cloud
| ประเภท | ตัวอย่าง | ข้อดี | ข้อจำกัด |
|---|---|---|---|
| Hardware Appliance | F5 BIG-IP, Citrix ADC, A10 Networks | ประสิทธิภาพสูงสุด, ฟีเจอร์ครบ, ใช้ได้ On-prem | แพง, Vendor Lock-in, Scaling ช้า |
| Software / Virtual | NGINX Plus, HAProxy, Envoy, Traefik, KEMP | ยืดหยุ่น, ราคาถูก/ฟรี, เรียกใช้ใน VM/Container/K8s ได้ | ต้องดูแลเอง, ประสิทธิภาพขึ้นกับ Host |
| Cloud Managed (LBaaS) | AWS ALB/NLB/GLB, Azure LB/Application Gateway, GCP Cloud Load Balancing, Cloudflare | Managed 100%, Auto-scale, Integrated Security, Pay-as-you-go | Vendor Lock-in, ความควบคุมน้อยกว่า, ค่าใช้จ่ายระยะยาว |
กรณีการใช้งาน (Use Cases)
- เว็บไซต์/แอปพลิเคชัน Traffice สูง (E-commerce, Streaming, Gaming)
- Microservices / Kubernetes (Ingress Controller, Service Mesh Gateway)
- API Gateway (Rate Limiting, Auth, Transformation)
- Multi-region / Disaster Recovery (GSLB)
- Zero Trust Network Access (ZTNA) Entry Point
Load Balancer ใน AWS (ตัวอย่างยอดนิยม)
- Application Load Balancer (ALB) - L7, รองรับ Host/Path-based Routing, WebSockets, HTTP/2, gRPC, WAF Integration, Lambda Targets
- Network Load Balancer (NLB) - L4, Ultra-low latency, Millions req/sec, Static IP, Preserve Source IP, TLS Termination (ใหม่)
- Gateway Load Balancer (GWLB) - สำหรับ Virtual Appliances (Firewall, IDS/IPS) - Transparent Bump-in-the-wire
- Classic Load Balancer (CLB) - Legacy (ไม่แนะนำใช้ใหม่)
สรุป
Load Balancer เป็นองค์ประกอบสำคัญของสถาปัตยกรรมระบบสมัยใหม่ ไม่เพียงแต่เพิ่มประสิทธิภาพและความพร้อมใช้งาน แต่ยังเป็น จุดควบคุมความปลอดภัยกลาง (Security Control Point) ที่มีประสิทธิภาพ การเลือกประเภทและคอนฟิกที่ถูกต้อง (L4 vs L7, SSL Termination, WAF, Health Checks) สำคัญไม่แพ้การเลือกฮาร์ดแวร์