AI Solution Architect: from System Analyst to AI Architect
บทที่ 2/12

Role & Architecture Fundamentals

Architecture Fundamentals & Decisions

เขียน architecture ด้วย C4 model ชั่ง trade-off ของ quality attributes อย่าง scalability, security, resilience และ compliance บันทึก decision ด้วย ADR และสร้าง reference architecture ที่ reuse ได้

⏱ ประมาณ 30 นาที

Architecture คือ ชุด decisions ที่เปลี่ยนทีหลังได้ยาก เช่น จะเก็บ customer data ไว้ที่ไหน ระบบคุยกันแบบ synchronous หรือผ่าน events และจะใช้ model จาก provider รายใด บทนี้ให้เครื่องมือสามอย่างที่ architect ใช้ทุกวัน ได้แก่ views สำหรับสื่อสาร design (C4) กรอบคิดสำหรับชั่ง trade-off (quality attributes) และวิธีบันทึก decision (ADR)

C4 model: zoom in one level at a time

C4 model ของ Simon Brown แบ่งการเล่า design เป็น 4 levels เหมือนแผนที่ที่ zoom เข้าไปเรื่อย ๆ

LevelแสดงอะไรAudience หลัก
1. System Contextระบบของเราหนึ่งกล่อง users และ external systems ที่เกี่ยวข้องexecutives, business
2. Containerหน่วยที่ deploy แยกกัน เช่น app, API, database, indexarchitects, infra, security
3. Componentcomponents ภายใน container หนึ่งdev team
4. Codeclasses, functions (มักไม่ต้องวาด generate จากโค้ดได้)developers
C4 สองระดับ: System Context แสดง customer ใช้ AI Assistant ซึ่งเชื่อมกับ legacy systems คือ Core Banking และ CRM ส่วน Container แสดงภายใน AI Assistant ว่า Web/Mobile app เรียก API Gateway ผ่าน HTTPS ไปยัง Orchestrator ซึ่งเรียก Search index ของ policy documents และ LLM service
Context level ใช้เล่าให้ executives ฟัง Container level ใช้คุยเรื่อง deployment และ security

Quality attributes & trade-offs

Requirements ที่ SA คุ้นเคยส่วนใหญ่เป็น functional (ระบบต้องทำอะไร) แต่สิ่งที่กำหนดรูปร่างของ architecture จริง ๆ คือ quality attributes หรือ non-functional requirements (NFR) ว่าระบบต้องทำได้ “ดีแค่ไหน”

Quality attributeTacticsTrade-off
Scalabilityautoscale, cache, queuecost และ complexity เพิ่ม
Resilienceretry, circuit breaker, multi-regioncost ราว 2 เท่า, data sync
Securityprivate network, encryption, least privilegelatency และ ops work เพิ่ม
Compliancedata residency, audit log, retentionตัวเลือก region และ model น้อยลง
Latency / costmodel ที่เล็กลง, response cachequality อาจลดลง

ไม่มี option ที่ดีทุกด้าน ทุก tactic มี trade-off

กฎสำคัญคือ quality attribute ต้อง measurable ไม่ใช่แค่คำคุณศัพท์

VagueMeasurable
ระบบต้องเร็วp95 time-to-first-token ≤ 2 s
ระบบต้องรองรับ users มากรองรับ 200 requests/s ใน peak hour
ระบบต้องเสถียรavailability 99.9% ต่อเดือน
ต้อง securecustomer data ไม่ออกนอก region ที่กำหนด และทุก access มี audit log

เทคนิคที่ใช้ได้ดีคือ quality attribute scenario เขียนเป็นประโยค “เมื่อ [event] เกิดขึ้นกับ [ส่วนใดของระบบ] ระบบต้อง [response อย่างไร] วัดด้วย [metric]” เช่น “เมื่อ LLM provider ล่ม ระบบต้องแจ้งว่ากำลัง transfer ให้ agent ภายใน 5 วินาที และไม่มี request ใดค้าง”

ADR: record your decisions

อีกหนึ่งปี ไม่มีใครจำได้ว่าทำไมทีมเลือก vector database ตัวนี้ Architecture Decision Record (ADR) คือ document สั้น ๆ หนึ่งเรื่องต่อหนึ่ง decision format ที่นิยม (ของ Michael Nygard) มี 5 หัวข้อ

ADR-007: ใช้ hybrid search แทน vector search อย่างเดียว
Status:       Accepted (2026-03-14)
Context:      คำถามลูกค้ามีเลขบัญชี รหัสผลิตภัณฑ์ และ keyword เฉพาะ
              ทดสอบแล้ว vector search อย่างเดียวพลาด exact match 18%
Decision:     ใช้ hybrid search (keyword + vector) และ rerank top 20
Consequences: + recall ดีขึ้นใน test set, ใช้ managed service เดิมได้
              − index ใหญ่ขึ้น cost เพิ่ม, ต้อง tune analyzer ภาษาไทย

ADR ที่ดี บอก trade-off อย่างตรงไปตรงมา และเมื่อ decision เปลี่ยน ให้เขียน ADR ใหม่ที่ “supersedes” ฉบับเดิม ไม่ลบของเก่า เพื่อให้เห็น history

Reference architecture & reusable components

เมื่อหลายทีมสร้าง chatbot ของตัวเอง แต่ละทีมจะแก้ปัญหาเดิมซ้ำ (authentication, content filtering, logging) และแก้ไม่เหมือนกัน architect จึงสร้าง

  • Reference architecture standard design ของ use case ที่พบบ่อย พร้อม ADRs ที่ตัดสินใจไว้แล้ว ทีมใหม่เริ่มจาก design นี้แทนที่จะเริ่มจากศูนย์
  • Reusable components / platform services เช่น AI gateway กลางที่ทุกทีมเรียกใช้ ซึ่งคุม quota, logging และ content filtering ไว้ที่จุดเดียว

ผลคือ dev teams ทำงานเร็วขึ้น และ governance ตรวจได้ง่ายขึ้น เพราะทุกระบบผ่าน standard เดียวกัน

แบบทดสอบ

ถ้าต้องอธิบายระบบให้ executives ฟังใน 1 นาที ควรใช้ C4 level ใด
ข้อใดเป็น quality attribute ที่เขียนได้ถูกต้อง
หัวข้อใดของ ADR บอกว่า decision นี้ยอม trade-off อะไรบ้าง
เมื่อ decision เดิมเปลี่ยน ควรจัดการ ADR อย่างไร
ประโยชน์หลักของ reference architecture คือข้อใด