
DNS Load Balancing และ GSLB: กระจาย Traffic ด้วย DNS
DNS Load Balancing คือวิธีกระจาย traffic ไปยัง servers หลายตัวโดยใช้ DNS เป็นตัวกลาง เมื่อ client query domain name DNS จะตอบด้วย IP addresses ที่แตกต่างกันแต่ละครั้ง (round-robin) หรือเลือก IP ที่เหมาะสมที่สุดตาม location, health, load ของ server ทำให้ traffic กระจายอัตโนมัติ
GSLB (Global Server Load Balancing) ขยายแนวคิดนี้ไปสู่ระดับ global กระจาย traffic ข้าม data centers หลายแห่งทั่วโลก เพื่อให้ users เข้าถึง server ที่ใกล้ที่สุดหรือ available ที่สุด เมื่อ data center หนึ่งล่ม DNS จะหยุดส่ง traffic ไปที่นั่นอัตโนมัติ บทความนี้จะอธิบายทั้ง DNS load balancing และ GSLB
DNS Load Balancing Methods
| Method | วิธีการ | ข้อดี | ข้อเสีย |
|---|---|---|---|
| Round-Robin DNS | ตอบ IP สลับกันทุกครั้ง | ง่ายมาก ไม่ต้องใช้ hardware พิเศษ | ไม่รู้ server health ไม่รู้ load |
| Weighted Round-Robin | ตอบ IP ตาม weight (server แรงกว่า = traffic มากกว่า) | กระจายตาม capacity | ยังไม่รู้ real-time load |
| Geo-based (GeoDNS) | ตอบ IP ตาม location ของ client | Users ได้ server ใกล้ = เร็ว | GeoIP database อาจไม่แม่น |
| Latency-based | ตอบ IP ของ server ที่ latency ต่ำที่สุด | Best performance | ต้องวัด latency ตลอดเวลา |
| Health-check based | ตอบเฉพาะ IP ของ server ที่ healthy | Automatic failover | ต้องมี monitoring |
Round-Robin DNS
วิธีง่ายที่สุด
วิธีทำ: เพิ่ม A records หลายตัวสำหรับ domain เดียวกัน เช่น www.example.com → 1.1.1.1, www.example.com → 2.2.2.2, www.example.com → 3.3.3.3 DNS จะตอบสลับ IP ทุกครั้งที่มี query
ข้อจำกัด: ไม่รู้ว่า server ตัวไหนล่ม (ยังส่ง traffic ไป) ไม่รู้ว่า server ตัวไหน load เยอะ DNS caching ทำให้ distribution ไม่เท่ากัน ไม่สามารถ route ตาม geography
GSLB Architecture
| Component | บทบาท |
|---|---|
| Authoritative DNS | DNS server ที่ตอบ query สำหรับ domain (intelligent responses) |
| Health Monitors | ตรวจสอบ server/site health ตลอดเวลา |
| GeoIP Database | ระบุ location ของ client จาก IP address |
| Load Metrics | ข้อมูล real-time load ของแต่ละ site |
| Policy Engine | ตัดสินใจว่าจะตอบ IP ไหน ตามกฎที่กำหนด |
GSLB Providers
| Provider | ประเภท | จุดเด่น | ราคา |
|---|---|---|---|
| Cloudflare | Cloud DNS + CDN | Global network, easy setup, DDoS protection | Free plan available |
| AWS Route 53 | Cloud DNS | Latency/Geo/Failover routing, AWS integration | $0.50/zone + queries |
| Azure Traffic Manager | Cloud DNS | Performance/Geographic/Priority routing | Pay per query |
| Google Cloud DNS | Cloud DNS | 100% SLA, global anycast | $0.20/zone + queries |
| F5 BIG-IP DNS (GTM) | Hardware/Virtual | Enterprise GSLB, deep health checks | $$$ |
| Citrix ADC (GSLB) | Hardware/Virtual | Enterprise GSLB + ADC | $$$ |
| NS1 (IBM) | Cloud DNS | Advanced traffic steering, filter chains | Per query |
AWS Route 53 Routing Policies
| Policy | วิธีการ | Use Case |
|---|---|---|
| Simple | Round-robin (หลาย IPs) | Basic load distribution |
| Weighted | กระจายตาม weight (70/30) | Canary deployment, A/B testing |
| Latency-based | Route ไป region ที่ latency ต่ำสุด | Global apps ที่ต้องการ low latency |
| Geolocation | Route ตาม country/continent ของ client | Content localization, compliance |
| Failover | Primary → Secondary เมื่อ primary fail | DR (disaster recovery) |
| Multivalue Answer | Round-robin + health checks | Simple LB with health checking |
Health Checks
| Check Type | วิธี | เมื่อไหร่ใช้ |
|---|---|---|
| TCP | ตรวจว่า port เปิด | Basic connectivity check |
| HTTP/HTTPS | ส่ง HTTP request ตรวจ status code + content | Web application health |
| DNS | ส่ง DNS query ตรวจ response | DNS server health |
| Calculated | รวม health checks หลายตัว | Complex health criteria |
DNS TTL Strategy
| TTL | ข้อดี | ข้อเสีย | เหมาะกับ |
|---|---|---|---|
| Short (30-60s) | Failover เร็ว DNS change เร็ว | DNS query เยอะ load สูง | GSLB, DR failover |
| Medium (300-600s) | Balance ระหว่าง speed + cache | Failover 5-10 นาที | ทั่วไป |
| Long (3600s+) | DNS query น้อย cache ดี | Failover ช้ามาก | Static content, CDN |
DNS LB vs Hardware LB
| คุณสมบัติ | DNS Load Balancing | Hardware/Software LB (L4/L7) |
|---|---|---|
| Scope | Global (ข้าม data centers) | Local (ภายใน data center) |
| Granularity | Per DNS query (coarse) | Per connection/request (fine) |
| Health Checks | Slow (DNS TTL dependent) | Fast (real-time) |
| Session Persistence | ไม่ได้ (DNS caching based) | ได้ (cookie, IP) |
| SSL Termination | ไม่ได้ | ได้ |
| Cost | ต่ำ (cloud DNS) | สูง (hardware/license) |
Best Practice: ใช้ทั้งคู่ร่วมกัน DNS GSLB กระจาย traffic ข้าม sites → Hardware/Software LB กระจายภายใน site
ทิ้งท้าย: DNS = Layer แรกของ Load Balancing
DNS Load Balancing เป็นวิธีง่ายและถูกที่สุดในการกระจาย traffic GSLB ช่วย failover ข้าม data centers อัตโนมัติ ใช้ cloud DNS (Route 53, Cloudflare) สำหรับ GSLB ตั้ง TTL สั้นสำหรับ failover scenarios รวม DNS LB + L4/L7 LB สำหรับ complete solution
อ่านเพิ่มเติมเกี่ยวกับ DNS Server Configuration และ Network Disaster Recovery ที่ siamlancard.com หรือจาก icafeforex.com และ siam2r.com