Load Balancing: L4/L7, HAProxy, NGINX, AWS ALB/NLB, GSLB และ Application Delivery

Load Balancing: L4/L7, HAProxy, NGINX, AWS ALB/NLB, GSLB และ Application Delivery

Load Balancing กระจาย traffic ไปยัง backend servers เพื่อ scalability และ high availability L4 Load Balancing ทำงานที่ transport layer (TCP/UDP), L7 ทำงานที่ application layer (HTTP/HTTPS), HAProxy เป็น open-source high-performance load balancer, NGINX เป็น web server + reverse proxy + LB, AWS ALB/NLB เป็น managed cloud load balancers, GSLB กระจาย traffic ข้าม data centers และ Application Delivery รวมทุกอย่างเป็น platform

ทุก web application ที่มี traffic สูง ต้องใช้ load balancer: single server handle ได้จำกัด (เช่น 10,000 concurrent connections), load balancer กระจาย traffic ไปหลาย servers → scale horizontally ถ้า server ตัวหนึ่ง fail → load balancer route ไป servers ที่เหลือ → zero downtime Netflix ใช้ load balancing หลายชั้นเพื่อ serve 250M+ subscribers

L4 vs L7 Load Balancing

Feature L4 (Transport) L7 (Application)
Layer TCP/UDP (IP + Port) HTTP/HTTPS (URL, headers, cookies)
Decision Based On Source/Dest IP, Port URL path, hostname, headers, cookies, content type
Performance Faster (no payload inspection) Slower (parse HTTP, SSL termination)
SSL Termination Pass-through (no inspection) Terminate SSL → inspect → re-encrypt or plaintext to backend
Content Routing ไม่ได้ (ไม่เห็น content) /api → API servers, /static → CDN, /ws → WebSocket servers
Use Case TCP services (database, SMTP, gaming) Web applications (HTTP routing, API gateway)
Examples AWS NLB, HAProxy TCP mode, LVS AWS ALB, HAProxy HTTP mode, NGINX, Envoy

Load Balancing Algorithms

Algorithm How Best For
Round Robin Rotate ทีละ server ตามลำดับ Equal-capacity servers, stateless apps
Weighted Round Robin Round robin แต่ server แข็งกว่าได้ weight มากกว่า Mixed-capacity servers
Least Connections ส่งไป server ที่มี active connections น้อยที่สุด Long-lived connections (WebSocket, database)
IP Hash Hash source IP → always same server (sticky) Session persistence without cookies
Least Response Time ส่งไป server ที่ response เร็วที่สุด Heterogeneous backends (different response times)
Random Random selection (with power of two choices) Large server pools (simple, effective)

HAProxy

Feature รายละเอียด
คืออะไร Open-source, high-performance TCP/HTTP load balancer and proxy
Performance Handle 1M+ concurrent connections, 100K+ requests/sec on single instance
Modes TCP mode (L4) + HTTP mode (L7) — both in single config
Health Checks TCP, HTTP (status code, body), custom scripts — remove unhealthy backends
SSL SSL termination, SSL passthrough, SSL re-encryption
ACLs Rich ACL system for routing: path, headers, cookies, source IP, SNI
Stats Built-in stats page (real-time dashboard) + Prometheus exporter
Used By GitHub, Stack Overflow, Reddit, Airbnb, Instagram

NGINX

Feature รายละเอียด
คืออะไร Web server + reverse proxy + load balancer + HTTP cache
Architecture Event-driven, non-blocking I/O → handle 10,000+ concurrent connections efficiently
Load Balancing Round robin, least connections, IP hash, random (upstream module)
L7 Features URL routing, header manipulation, caching, rate limiting, gzip compression
NGINX Plus Commercial version: active health checks, session persistence, DNS service discovery, dashboard
vs HAProxy NGINX: web server + LB (better for static content, caching) | HAProxy: pure LB (better for complex routing)
Market Share 34%+ of all websites use NGINX (most popular web server)

AWS Load Balancers

Type Layer Use Case Features
ALB (Application) L7 (HTTP/HTTPS) Web apps, microservices, containers Path/host routing, WebSocket, gRPC, WAF integration
NLB (Network) L4 (TCP/UDP/TLS) High performance, static IP, gaming Millions of RPS, static IP/EIP, ultra-low latency
CLB (Classic) L4 + L7 (legacy) Legacy EC2-Classic Deprecated — migrate to ALB/NLB
GWLB (Gateway) L3 (IP) Inline security appliances Route traffic through firewalls/IDS transparently

GSLB (Global Server Load Balancing)

Feature รายละเอียด
คืออะไร Distribute traffic across multiple data centers/regions globally
DNS-Based Return different IP based on client location, health, load → DNS resolves to nearest DC
Anycast Same IP advertised from multiple locations → BGP routes to nearest (CDN approach)
Policies Geographic (nearest), weighted (ratio), failover (primary/backup), latency-based
Health Checks Monitor each DC’s health → remove unhealthy DC from DNS/anycast
Products AWS Route 53, Cloudflare, F5 BIG-IP DNS, NS1, Akamai GTM

ทิ้งท้าย: Load Balancing = Scale, Availability, Performance

Load Balancing L4 vs L7: L4 (TCP/UDP, fast, no content inspection) vs L7 (HTTP, content routing, SSL termination) Algorithms: round robin, weighted, least connections, IP hash, least response time, random HAProxy: pure LB (1M+ connections), rich ACLs, TCP+HTTP modes, used by GitHub/Reddit NGINX: web server + LB + cache, event-driven, 34% market share, NGINX Plus for enterprise AWS: ALB (L7 web), NLB (L4 performance), GWLB (security appliances) GSLB: DNS-based or anycast, geographic/latency routing, multi-DC failover Key: L4 for raw performance, L7 for intelligent routing — most apps need L7 with proper health checks and algorithms

อ่านเพิ่มเติมเกี่ยวกับ Kubernetes Networking CNI Service Mesh Ingress และ Cloud Networking VPC Transit Gateway ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com

จัดส่งรวดเร็วส่งด่วนทั่วประเทศ
รับประกันสินค้าเคลมง่าย มีใบรับประกัน
ผ่อนชำระได้บัตรเครดิต 0% สูงสุด 10 เดือน
สะสมแต้ม รับส่วนลดส่วนลดและคะแนนสะสม

© 2026 SiamLancard — จำหน่ายการ์ดแลน อุปกรณ์ Server และเครื่องพิมพ์ใบเสร็จ

SiamLancard
Logo
Free Forex EA Download — XM Signal · EA Forex ฟรี
iCafeForex.com - สอนเทรด Forex | SiamCafe.net
Shopping cart