01 Enterprise Architecture Overview
ระบบ OSM ออกแบบตามหลัก Modern Application Development (12-Factor App) ตามที่ TOR ข้อ 4.3 กำหนด โดยใช้สถาปัตยกรรม Microservices บน Kubernetes (K8s) รองรับ Responsive Design ทั้ง PC, Smartphone, และ Tablet
02 Microservices Architecture
ระบบออกแบบเป็น 9 Microservices แต่ละ Service มีหน้าที่ชัดเจน (Single Responsibility) สื่อสารกันผ่าน REST API และ Event Bus (Message Queue) สามารถ Scale แต่ละ Service ได้อิสระ
12-Factor App Compliance (TOR ข้อ 4.3)
| Factor | Implementation |
|---|---|
| I. Codebase | GitLab Monorepo / Multi-repo per service |
| II. Dependencies | package.json / requirements.txt — locked versions |
| III. Config | Environment Variables + Vault Secret Manager |
| IV. Backing Services | PostgreSQL, Redis, S3, SMTP — attached via env config |
| V. Build, Release, Run | Docker multi-stage build → Helm release → K8s rollout |
| VI. Processes | Stateless containers, session in Redis |
| VII. Port Binding | Each service exposes HTTP port independently |
| VIII. Concurrency | Horizontal Pod Autoscaler (HPA) per service |
| IX. Disposability | Fast startup/shutdown, graceful drain connections |
| X. Dev/Prod Parity | Docker Compose (dev) = K8s (prod) same images |
| XI. Logs | stdout → Fluentd → Elasticsearch → Kibana |
| XII. Admin Processes | K8s Jobs / CronJobs for migrations, scripts |
03 Data Security & PDPA Compliance
ระบบออกแบบ Security ตาม Defense-in-Depth หลายชั้น ครอบคลุมทั้ง Network, Application, Data, และ User Level พร้อมรองรับ พ.ร.บ. คุ้มครองข้อมูลส่วนบุคคล พ.ศ. 2562 (PDPA)
🔐 Authentication Flow (SSO — TOR ข้อ 4.12)
Web Browser
React Frontend
OIDC Provider
LDAP/Active Dir
Access + Refresh
📋 PDPA Compliance Framework (พ.ร.บ. 2562)
Security Scan Integration (TOR ข้อ 4.9)
| ประเภท | เครื่องมือ | จุดที่ Scan | ความถี่ |
|---|---|---|---|
| SAST | SonarQube | Source Code (ทุก Commit) | ทุก CI Pipeline |
| DAST | OWASP ZAP | Running Application | สัปดาห์ละ 1 ครั้ง |
| SCA | Snyk / Trivy | Dependencies + Docker Image | ทุก CI Pipeline |
| Secret Scan | GitLeaks | Git Repository | ทุก Commit |
| Pentest | Manual + Automated | Full System | ก่อน Go-Live + รายไตรมาส |
04 System Scalability & Performance
ระบบออกแบบเพื่อรองรับการขยายตัว (Scale-out) ทั้ง Horizontal และ Vertical ตาม TOR ข้อ 4.8 (Kubernetes) และข้อ 15.9 (Performance Test)
↔️ Horizontal Scaling (Scale-Out)
Kubernetes HPA — Pod Autoscaler ตาม CPU/Memory
Min 2, Max 10 Pods ต่อ Service
Load Balancer — Round-robin distribution
Database Read Replica — PostgreSQL Streaming Replication
↕️ Vertical Scaling (Scale-Up)
Resource Requests/Limits — K8s Resource Quota
CPU: 0.5–2 cores / Memory: 512MB–2GB ต่อ Pod
PV Dynamic Provisioning — Storage auto-expand
PostgreSQL Tuning — shared_buffers, work_mem
Performance Targets (TOR ข้อ 15.9)
| Metric | Target SLA | วิธีวัด |
|---|---|---|
| Response Time (API) | < 500ms (P95) | Prometheus + Grafana |
| Page Load Time | < 3 seconds | Lighthouse / WebPageTest |
| Concurrent Users | ≥ 500 users | k6 / JMeter Load Test |
| Uptime | ≥ 99.5% | Uptime Kuma / StatusPage |
| Database Query | < 200ms (P95) | pg_stat_statements |
| File Upload | < 5s (50MB file) | Integration Test |
Caching Strategy
Redis Cache
Session, JWT Token, Frequently-accessed data, Rate Limiter
Browser Cache
Static assets (JS/CSS/images), Service Worker for PWA offline
CDN Cache
Static files, Generated reports (PDF/Excel), Image thumbnails
Query Cache
PostgreSQL prepared statements, Materialized Views for dashboards
05 DevSecOps & CI/CD Pipeline
ตาม TOR ข้อ 4.8 ระบบต้องรองรับ Continuous Integration and Continuous Deployment (CI/CD) บน DevSecOps Platform (Kubernetes) โดยใช้ GitLab CI/CD เป็น Pipeline Runner
Git Push
ESLint/Pylint
Unit + E2E
SonarQube
Docker Image
Trivy Image
Harbor/ECR
K8s Helm
Kubernetes Deployment Architecture (TOR ข้อ 4.8, 4.16)
*.osm.pea.co.th
Production
UAT/Staging
Development
Primary + 2 Read Replica
3 nodes
3 nodes
06 API & External Integration
ตาม TOR ข้อ 4.4 ต้องเชื่อมต่อ API Web Service กับระบบภายนอก 4 ระบบหลักของ PEA พร้อมรองรับการเชื่อมต่อเพิ่มเติมในอนาคต
| ระบบภายนอก | Protocol | วัตถุประสงค์ | ข้อกำหนด TOR |
|---|---|---|---|
| 🏢 HR Data Platform | REST API | ดึงข้อมูลพนักงาน ตำแหน่ง หน่วยงาน | ข้อ 4.4 |
| 📧 PEA Email (SMTP) | SMTP/IMAP | แจ้งเตือน, ส่งรายงาน, OTP | ข้อ 4.4, 4.10 |
| 💳 Smart Payment (SAP) | REST / RFC | เบิกจ่ายเงิน, e-Receipt, e-Tax Invoice | ข้อ 4.4 |
| 🏛️ e-Procurement (e-GP) | REST API | เชื่อมข้อมูลจัดซื้อจัดจ้างภาครัฐ | ข้อ 2.12, 4.4 |
| ✍️ Digisign API | REST API | ลงลายเซ็นดิจิทัล (Digital Signature) | ข้อ 4.18 |
| 🔐 Keycloak SSO | OIDC/OAuth2 | Single Sign-On + AD Integration | ข้อ 4.12 |
API Gateway Architecture
Web/Mobile
Auth + Rate Limit
Path-based routing
Business Logic
PostgreSQL
07 Monitoring, Logging & Alerting
ตาม TOR ข้อ 4.15 (Monitoring Integration) และข้อ 4.20 (Audit Log) ระบบต้องมีการ Monitor ครบถ้วนทั้ง Infrastructure, Application, และ Business Metrics
• Request latency (P50/P95)
• Error rate per service
• Active connections
• Custom business metrics
• Audit trail (TOR 4.20)
• Error tracking
• Security events
• API request/response log
• Request flow mapping
• Service dependency
• Latency breakdown
• Error propagation
🔔 Alert Rules (TOR ข้อ 4.17)
| Alert | Condition | ช่องทางแจ้ง | Severity |
|---|---|---|---|
| CPU High | CPU > 80% for 5 min | PEA Email + Line | Critical |
| Memory High | Memory > 85% | PEA Email + Line | Critical |
| Error Rate | >1% of requests 5xx | PEA Email + Grafana | Warning |
| Disk Full | Disk > 90% | PEA Email | Critical |
| Pod CrashLoop | Pod restart > 3 in 5 min | PEA Email + Line | Critical |
| สัญญาใกล้หมด | 30 วันก่อนหมดอายุ | PEA Email + In-app | Info |
| SSL Cert Expiry | 30 วันก่อนหมด | PEA Email | Warning |
08 Deployment Recommendation
จากการวิเคราะห์ TOR ข้อ 22 (สถานที่ส่งมอบ: 200 ถ.งามวงศ์วาน นนทบุรี) และข้อ 4.8 (Kubernetes) แนะนำ 3 ทางเลือกในการ Deploy โดยเรียงตามความเหมาะสม
เหมาะสมที่สุดเนื่องจาก PEA มี Data Center เอง ข้อมูลอยู่ภายในองค์กร ตอบ Security/PDPA ได้ดี และเป็นไปตาม TOR
Option A: PEA On-Premise (แนะนำ) ⭐
Users access via browser
Network perimeter security
TLS termination + traffic routing
K8s v1.28+ — Rancher / kubeadm
Server Specification (Minimum)
| Role | จำนวน | CPU | RAM | Storage | OS |
|---|---|---|---|---|---|
| K8s Master | 3 | 4 vCPU | 8 GB | 100 GB SSD | Ubuntu 22.04 / RHEL 8 |
| K8s Worker | 3 | 8 vCPU | 16 GB | 200 GB SSD | Ubuntu 22.04 / RHEL 8 |
| PostgreSQL Primary | 1 | 8 vCPU | 32 GB | 500 GB SSD | Ubuntu 22.04 |
| PostgreSQL Replica | 2 | 4 vCPU | 16 GB | 500 GB SSD | Ubuntu 22.04 |
| Redis + Elasticsearch | 1 | 4 vCPU | 16 GB | 200 GB SSD | Ubuntu 22.04 |
| GitLab CI Runner | 1 | 4 vCPU | 8 GB | 200 GB SSD | Ubuntu 22.04 |
| รวม | 11 VMs | 60 vCPU | 144 GB | 3 TB |
Option B: Hybrid (On-Premise + Cloud)
🏢 On-Premise
Database (PostgreSQL), Keycloak SSO, File Storage — ข้อมูลสำคัญอยู่ภายในเครือข่าย PEA
☁️ Cloud (AWS/Azure/GCP)
Application Pods (EKS/AKS/GKE), CDN, Monitoring — ใช้ managed K8s ลดภาระดูแล infra
Option C: Full Cloud (PDPA-Compliant)
Deploy ทั้งหมดบน Cloud Provider ที่มี Data Center ใน Thailand (AWS Bangkok / Azure Southeast Asia) — เหมาะกรณี PEA ไม่มี On-Premise K8s infrastructure พร้อม
🚀 Deployment Process (TOR ข้อ 4.1.4)
main branch
+ Scan
Docker Image
to UAT
Approval
Deploy Prod
09 Disaster Recovery & Backup
Backup Strategy
| ประเภท | ความถี่ | Retention | วิธีการ |
|---|---|---|---|
| Database (Full) | ทุกวัน 02:00 | 30 วัน | pg_dump + compression → NAS |
| Database (WAL) | ทุก 5 นาที | 7 วัน | WAL archiving + PITR |
| File Storage | ทุกวัน | 90 วัน | rsync to backup NAS |
| K8s Config | ทุกวัน | 30 วัน | Velero backup → S3 |
| GitLab Repo | ทุกวัน | ไม่จำกัด | Git mirror to DR site |
Recovery Objectives
RPO (Recovery Point Objective)
5 นาที
สูญเสียข้อมูลไม่เกิน 5 นาที (WAL streaming)
RTO (Recovery Time Objective)
30 นาที
กู้คืนระบบเต็มรูปแบบภายใน 30 นาที
HA (High Availability)
99.5%
Uptime ≥ 99.5% ตลอดปี (downtime ≤ 43.8 ชม.)