APIs, Cloud-native & Integration
Cloud-native on Azure
Building blocks ของระบบ cloud-native ตั้งแต่ landing zone, containers และ serverless compute, private networking และ Entra ID, resilience patterns อย่าง retry, circuit breaker และ multi-region, availability math และ reference architecture ของ GenAI app บน Azure
Cloud-native ไม่ได้แปลว่า “lift-and-shift ขึ้น cloud” แต่หมายถึง design ให้ใช้จุดแข็งของ cloud คือ autoscaling, managed services, infrastructure as code และ design for failure เพราะ components ล้มได้เสมอ บทนี้อธิบาย concepts แบบ vendor-neutral ก่อน แล้ว map เข้ากับ Azure (ชื่อ services ณ ปี 2026)
Landing zone: build the foundation first
องค์กรใหญ่ไม่ให้แต่ละทีมสร้าง subscription ตามใจ แต่เตรียม landing zone ไว้ก่อน คือ foundation กลางที่กำหนดไว้แล้ว
- Management groups และ subscriptions แยกตาม environment (dev, test, prod)
- Network แบบ hub-and-spoke มี firewall และ connectivity กับ on-premises data center ที่ hub
- Azure Policy enforce rules เช่น ห้ามสร้าง resources นอก allowed regions ห้ามเปิด public endpoints
- Centralized identity, logging และ cost management
Solution architect มักไม่ได้สร้าง landing zone เอง แต่ต้อง design ให้อยู่ใน guardrails ของมัน ได้
Choosing compute
| Option | ลักษณะ | เหมาะกับ |
|---|---|---|
| Azure Functions | serverless, event-driven, pay-per-use | งานสั้น ๆ ตาม events เช่น process document ที่ upload |
| Azure Container Apps | managed containers, autoscale (scale to zero ได้) | APIs และ orchestrators ส่วนใหญ่ ทีมไม่อยากดูแล Kubernetes |
| Azure Kubernetes Service (AKS) | Kubernetes เต็มรูปแบบ | องค์กรที่มี platform team และต้องการ fine-grained control |
| App Service | managed web/API hosting | web apps แบบดั้งเดิม |
Networking & identity
Private endpoint ให้ PaaS services เช่น Azure OpenAI, AI Search และ Storage มี private IP ภายใน virtual network แล้ว ปิด public network access customer data จึงวิ่งใน private network เป็น baseline requirement ของงานธนาคาร
Microsoft Entra ID (เดิมชื่อ Azure Active Directory) จัดการ identity ทั้งคนและ workloads หลักสำคัญคือใช้ managed identity ให้ app authenticate กับ services อื่นโดย ไม่มี keys หรือ passwords ในโค้ด ส่วน secrets ที่หลีกเลี่ยงไม่ได้เก็บใน Key Vault
Resilience patterns
| Pattern | แก้ปัญหา | ข้อควรระวัง |
|---|---|---|
| Timeout | request ค้างไม่สิ้นสุด | ตั้งทุก network call |
| Retry with backoff | transient errors (เช่น HTTP 429, 503) | exponential backoff + jitter และ retry เฉพาะ idempotent requests |
| Circuit breaker | downstream ล่มนาน retry ซ้ำ ๆ ยิ่งทำให้แย่ | เมื่อ fail ติดกันเกิน threshold ให้ “open circuit” ตอบด้วย fallback ทันที แล้วทดลองใหม่เป็นระยะ |
| Fallback | primary service ใช้ไม่ได้ | เช่น LLM ล่ม → “กำลังโอนสายให้พนักงาน” |
| Multi-region | ทั้ง region ล่ม | cost เกือบ 2 เท่า, data replication และต้องอยู่ใน regions ที่ regulation อนุญาต |
สำหรับ LLM โดยเฉพาะ HTTP 429 (quota exceeded) เกิดบ่อยมาก AI gateway จึงมัก load balance ไปหลาย deployments หรือหลาย regions และ failover ไปตัวสำรองเมื่อตัวหลักเต็ม
Availability math
เมื่อ request ต้องผ่านหลาย components in series availability รวมคือ ผลคูณ
เช่น app 99.9% เรียก LLM 99.95% → 0.999 × 0.9995 ≈ 0.9985 หรือ 99.85% ต่ำกว่าทุก component ที่นำมาต่อกัน
เมื่อมีสองชุด in parallel (ระบบยังทำงานถ้าชุดใดชุดหนึ่งยังอยู่)
เช่น สอง regions region ละ 99.9% → 1 − 0.001² = 0.999999 ในทางทฤษฎี (ในความจริงต่ำกว่านี้ เพราะสอง regions มักล้มด้วย common cause ได้ เช่น deploy โค้ดที่มี bug)
แปลงเป็น downtime 99.9% ต่อเดือน 30 วัน ยอม downtime ได้ 0.1% × 30 × 24 × 60 = 43.2 นาที ตัวเลขนี้ช่วยให้ executives เห็นภาพว่า “อีกหนึ่งเลข 9” มี cost เท่าไร
Reference architecture: GenAI app on Azure
| Layer | หน้าที่ | Azure services |
|---|---|---|
| Edge | load balancing, web attack protection | Front Door หรือ Application Gateway + WAF |
| App & orchestrator | RAG และ agent logic | Container Apps หรือ AKS |
| AI gateway | token quota, load balancing, logging | API Management |
| Models | LLM และ embeddings | Azure OpenAI ใน Microsoft Foundry |
| Knowledge | index และ document search | Azure AI Search + Blob Storage หรือ Data Lake |
| Security | identity, secrets, private network | Entra ID, managed identity, Key Vault, private endpoints |
| Observability | logs, traces, metrics, cost | Azure Monitor, Application Insights |
แบบทดสอบ
ระบบที่มี availability 99.5% ต่อเดือน (30 วัน) ยอม downtime ได้กี่นาที