Tài liệu kỹ thuật — On-Premise Infrastructure

Đề xuất Hạ tầng Triển khai
Chemical Management System (CMS)

On-Premise Physical Server · 160 Concurrent Users · Enterprise-Ready

📅 Ngày lập: 25/06/2026 🔖 Phiên bản: 1.0 🏭 Phạm vi: Production + HA

1. Tổng quan hệ thống

Người dùng đồng thời
160
Peak concurrent users
Peak throughput
320 req/s
Ước tính 2 req/s/user
Thời gian hoạt động
99.9%
SLA mục tiêu (HA mode)
Tầm nhìn mở rộng
3–5 năm
Không thay kiến trúc nền

Phạm vi chức năng

Core (ngay lúc đầu)
  • Chemical Master — Danh mục hóa chất
  • Warehouse Mgmt — Nhập / Xuất / Tồn kho
  • Approval Workflow — Luồng phê duyệt
  • Incident Management — Quản lý sự cố
  • SDS Management — Safety Data Sheet
  • Reporting & Dashboard
  • RBAC — Phân quyền
Future (giai đoạn 2)
  • ETL / Crawler job
  • ERP Integration (SAP, Oracle)
  • Notification Center (Email/SMS/Teams)
  • IoT Integration (cảm biến kho)
  • AI Analytics — dự báo tồn kho
Giả định khối lượng dữ liệu (5 năm)
Chemical master20.000 records
Inventory transactions~912.500 records
Workflow history~3.000.000 records
Incident records~100.000 records
Tổng DB (ước tính)50–100 GB
Storage cần (incl. backup)500 GB+

2. Stack Công nghệ đề xuất

Layer Công nghệ Lý do chọn Ghi chú
Load Balancer HAProxy + Keepalived Virtual IP, active-passive, health check L4/L7 Open Source
Reverse Proxy Nginx SSL termination, static file, gzip, rate limit Open Source
Application Java (Spring Boot) / .NET / Node.js Ecosystem mature, thread pool, tái sử dụng connection pool Theo ngôn ngữ team
Workflow Engine Camunda BPM / Activiti BPMN, audit log tích hợp, UI quản trị flow Tùy chọn
Database PostgreSQL 16 ACID, Partition Table, JSONB, Full Text Search, Streaming Replication Khuyến nghị
Cache / Session Redis 7 (Sentinel) Session, workflow state, dashboard cache, pub/sub Open Source
Search (tương lai) Elasticsearch Full-text search SDS/PDF, log analytics Giai đoạn 2
Message Queue RabbitMQ Async jobs, crawler, notification, đơn giản hơn Kafka cho quy mô này Giai đoạn 2
OS Ubuntu 22.04 LTS / Rocky Linux 9 LTS 5 năm, security patches, cộng đồng rộng Khuyến nghị
Container (tùy chọn) Docker + Docker Compose Môi trường nhất quán, rollback nhanh, không cần k8s ở quy mô này Tùy chọn
Monitoring Prometheus + Grafana Metrics server, alert, dashboard tổng quan Khuyến nghị
Log Management Loki + Promtail hoặc ELK Tập trung log, tìm kiếm nhanh Tùy chọn

3. Phương án Triển khai

⚡ Phương án A — Standard
Phù hợp: 160 concurrent, 300–500 users tổng, 3 năm đầu — chi phí thấp hơn
ServerVai tròCPURAMSSD
APPApplication + Nginx16 Core64 GB1 TB NVMe
DBPostgreSQL + Redis24 Core128 GB2 TB NVMe RAID1
BACKUPBackup + ETL + Reporting8 Core32 GB2 TB

⚠️ SPOF tại App Server — không phù hợp hệ thống vận hành nhà máy critical

🏆 Phương án B — High Availability (Khuyến nghị)
Phù hợp: nhà máy vận hành liên tục, yêu cầu uptime 99.9%, mở rộng lên 500+ user
ServerVai tròCPURAMSSD
LB01/LB02HAProxy + Keepalived (VIP)4 Core8 GB256 GB
APP01/APP02Application + Nginx (cluster)16 Core64 GB1 TB NVMe
REDIS01/02Redis Sentinel4 Core16 GB256 GB
DB01 (Primary)PostgreSQL Primary24 Core128 GB2 TB NVMe RAID1
DB02 (Standby)PostgreSQL Streaming Replica24 Core128 GB2 TB NVMe RAID1
BACKUPBackup + ETL + Monitoring8 Core32 GB4 TB HDD

✓ Không có SPOF — failover tự động DB và App


4. Kiến trúc Logical — Phương án HA

┌──────────────────────────────────────────┐ │ INTERNET / INTRANET │ └─────────────────┬────────────────────────────┘ │ ┌─────────────────▼────────────────────────────┐ │ VIRTUAL IP (Keepalived) │ │ HAProxy LB01 ←→ HAProxy LB02 │ │ (Active) (Passive / Standby) │ └──────────┬────────────────────────────────────┘ │ Round Robin / Least Connection ┌──────────▼──────────────────────────────┐ │ APP CLUSTER │ │ │ │ ┌─────────────┐ ┌─────────────┐ │ │ │ APP01 │ │ APP02 │ │ │ │ Nginx │ │ Nginx │ │ │ │ Spring Boot│ │ Spring Boot│ │ │ │ Scheduler │ │ Scheduler │ │ └──┴──────┬──────┘ └──────┬──────┘────┘ │ │ ┌─────────▼───────────────────▼──────────┐ │ REDIS SENTINEL CLUSTER │ │ REDIS01 (Master) ←→ REDIS02 (Replica) │ │ Session · Cache · Workflow State │ └──────────────────┬─────────────────────┘ │ ┌──────────────────▼─────────────────────┐ │ DATABASE CLUSTER │ │ │ │ ┌───────────────┐ Streaming ┌─────────────────┐ │ │ DB01 Primary │ ─────────────▶│ DB02 Standby │ │ │ PostgreSQL 16│ │ PostgreSQL 16 │ │ │ Read + Write │ │ Read / Failover │ │ └───────────────┘ └─────────────────┘ └─────────────────────────────────────────┘ │ ┌──────────────────▼─────────────────────┐ │ BACKUP & MONITORING SERVER │ │ pg_dump · WAL Archive · Prometheus │ │ Grafana · ETL/Crawler (giai đoạn 2) │ └─────────────────────────────────────────┘

5. Bill of Materials (BOM) — Phần cứng

5.1 Phương án B — HA Full (Khuyến nghị Production)

# Tên Server CPU RAM Storage Network Vai trò chính
1 LB01 4 Core (Intel/AMD) 8 GB ECC 256 GB SSD 2× 1GbE HAProxy Active + Keepalived
2 LB02 4 Core 8 GB ECC 256 GB SSD 2× 1GbE HAProxy Passive + Keepalived
3 APP01 16 Core (Xeon/EPYC) 64 GB ECC 1 TB NVMe 2× 10GbE Application + Nginx + Scheduler
4 APP02 16 Core 64 GB ECC 1 TB NVMe 2× 10GbE Application + Nginx (Standby/Scale)
5 REDIS01 4 Core 16 GB ECC 256 GB SSD 2× 10GbE Redis Master (Sentinel)
6 REDIS02 4 Core 16 GB ECC 256 GB SSD 2× 10GbE Redis Replica (Sentinel)
7 DB01 24 Core (Xeon/EPYC) 128 GB ECC 2× 2TB NVMe (RAID1) 2× 10GbE PostgreSQL Primary
8 DB02 24 Core 128 GB ECC 2× 2TB NVMe (RAID1) 2× 10GbE PostgreSQL Standby + Read Replica
9 BACKUP 8 Core 32 GB 4 TB HDD RAID5 2× 1GbE Backup + Monitoring + ETL (future)
Tổng CPU
104 Core
Tổng RAM
464 GB
Tổng Storage
~13 TB

5.2 Phương án A — Standard (Tiết kiệm chi phí)

#ServerCPURAMStorageVai trò
1APP16 Core64 GB1 TB NVMeNginx + Application + Redis + Scheduler
2DB24 Core128 GB2 TB NVMe RAID1PostgreSQL Primary
3BACKUP8 Core32 GB2 TBBackup + ETL + Reporting

6. Kiến trúc Mạng & Phân vùng VLAN

VLAN 10 — DMZ
10.10.10.0/24
Load Balancer LB01, LB02
Tiếp nhận traffic từ ngoài vào
VLAN 20 — Application
10.10.20.0/24
APP01, APP02, REDIS01, REDIS02
Internal application traffic
VLAN 30 — Database
10.10.30.0/24
DB01 (Primary), DB02 (Standby)
Isolated — không expose ra ngoài
VLAN 40 — Backup/Mgmt
10.10.40.0/24
BACKUP Server, Monitoring
Out-of-band management access

Firewall Rules tối thiểu

NguồnĐíchPortGhi chú
Internet/IntranetLB01/LB02 (DMZ)80, 443Chỉ mở HTTP/HTTPS
DMZAPP VLAN8080 (app port)Forward từ LB vào App
APP VLANDB VLAN5432 (PostgreSQL)App → DB only
APP VLANAPP VLAN6379 (Redis)App → Redis
DB VLANDB VLAN5432Replication DB01 → DB02
Backup VLANDB VLAN5432pg_dump / WAL archive
Admin IPAll VLAN22 (SSH)Whitelist IP quản trị
APP VLANBackup VLAN9090 (Prometheus)Metrics scraping

7. Sizing & Capacity Planning

CPU Sizing — Application Server
Concurrent users160
Avg req/s per user2 req/s
Peak throughput320 req/s
Capacity / 16-core node150–250 req/s
Số App node cần2 node (headroom 2×)
Safe capacity (2 node)300–500 req/s

Headroom ~2–3× giúp hấp thụ traffic spike và đảm bảo UX mượt mà khi có spike

Memory Sizing — Application Server
JVM / App heap16–24 GB
OS + buffer cache8 GB
Connection pools4 GB
Metaspace / off-heap4 GB
Safety margin12 GB
Tổng khuyến nghị64 GB / node
Database Sizing — PostgreSQL
shared_buffers32 GB (25% RAM)
effective_cache_size96 GB (75% RAM)
work_mem256 MB
max_connections200 (dùng PgBouncer pool)
DB size 5 năm50–100 GB
WAL + index overhead×2 = ~200 GB
Storage RAID1 mỗi node2 TB NVMe
Redis Sizing
Session (160 users × 50 KB)~8 MB
Dashboard cache~500 MB
Workflow state cache~1 GB
Pub/Sub buffer~500 MB
Tổng ước tính~2–4 GB dùng thực
RAM Redis node16 GB (dư rộng)

8. Backup & Disaster Recovery

Chiến lược Backup
LoạiTần suấtRetentionPhương thức
Full DB backup1 lần/ngày (02:00 AM)30 ngàypg_dump / pgBackRest
WAL archive15 phút7 ngàyWAL-G / pgBackRest
Application config1 lần/tuần90 ngàyrsync
Offsite backup1 lần/ngày7 bảnrsync → NAS ngoài
DR Targets
RPO
15 phút
Mất dữ liệu tối đa
RTO
1 giờ
Phục hồi hệ thống

DB Streaming Replication đảm bảo RPO < 1 phút trong trường hợp failover. WAL archive đảm bảo RPO < 15 phút cho các lỗi data corruption.


9. Monitoring & Observability

Infrastructure Metrics
  • CPU / Memory / Disk I/O per node
  • Network throughput in/out
  • Disk usage trend
  • Process health (systemd / docker)

Tool: Prometheus + node_exporter + Grafana

Application Metrics
  • Request rate & error rate (p95/p99)
  • JVM heap, GC pause
  • Active sessions
  • Workflow queue depth

Tool: Micrometer + Prometheus

Database Metrics
  • TPS, QPS, connections
  • Replication lag (Standby)
  • Table bloat / autovacuum
  • Slow query (pg_stat_statements)

Tool: postgres_exporter + pgBadger

Alert ngưỡng quan trọng

MetricWarningCriticalAction
CPU Usage (App)> 70%> 90%Scale app node / investigate
RAM Usage> 80%> 95%Review cache / heap settings
Disk Usage> 75%> 90%Expand / archive old data
DB Replication Lag> 30s> 120sInvestigate network / DB load
Request Error Rate> 1%> 5%Check app logs / rollback
Response time p95> 1s> 3sOptimize query / cache

10. Lộ trình Triển khai

Tuần 1–2 — Chuẩn bị hạ tầng
Cài đặt OS (Ubuntu 22.04 LTS / Rocky Linux 9) trên tất cả server. Cấu hình VLAN, Firewall, SSH key, NTP. Cài HAProxy + Keepalived (LB01/LB02). Thiết lập network bonding cho 10GbE links.
Tuần 3 — Database & Cache
Cài PostgreSQL 16 trên DB01/DB02. Cấu hình Streaming Replication + Failover (Patroni hoặc repmgr). Cài PgBouncer (connection pooler). Cài Redis Sentinel trên REDIS01/REDIS02. Test failover DB và Redis.
Tuần 4 — Application Deployment
Deploy application lên APP01/APP02 (Docker Compose hoặc systemd service). Cấu hình Nginx reverse proxy. Cài PgBouncer proxy layer. Test horizontal scaling và session persistence.
Tuần 5 — Monitoring & Backup
Cài Prometheus + node_exporter + postgres_exporter. Setup Grafana dashboards. Cấu hình pgBackRest / WAL-G cho PITR backup. Test restore từ backup. Cấu hình alert rules (email/Teams).
Tuần 6 — Load Testing & Handover
Load test với 160+ concurrent users (JMeter / k6). Kiểm tra DR scenario: tắt DB01, verify failover sang DB02. Bàn giao runbook, tài liệu vận hành. Go-live checklist.

11. Đánh giá Rủi ro

#Rủi roMức độBiện pháp giảm thiểu
1 DB Primary down, ảnh hưởng toàn bộ hệ thống HIGH DB02 Standby + Patroni/repmgr auto failover < 30s
2 App server down, request bị lỗi MEDIUM 2 App node, HAProxy health check tự loại bỏ node lỗi
3 Redis down, mất session MEDIUM Redis Sentinel failover tự động < 10s; session store có TTL
4 Data corruption / xóa nhầm HIGH PITR backup (Point-in-Time Recovery) với WAL archive 7 ngày
5 Storage đầy trong 5 năm LOW 2TB NVMe RAID1 >> 100GB data; thêm disk hoặc archive cold data
6 Performance giảm khi triển khai crawler/ETL MEDIUM Chạy crawler trên BACKUP server; sử dụng RabbitMQ queue không đồng bộ
7 LB single point of failure LOW HAProxy Active-Passive với Keepalived Virtual IP, failover < 2s

12. Kết luận & Khuyến nghị

Khuyến nghị: Phương án B — High Availability

Với hệ thống quản lý hóa chất vận hành nhà máy, tính liên tục nghiệp vụ là yếu tố tối quan trọng. Phương án HA loại bỏ mọi điểm lỗi đơn, đảm bảo SLA 99.9%, phục vụ 160 concurrent users với headroom ~2–3× cho growth trong 3–5 năm.

  • Không có SPOF nào trong luồng critical
  • DB failover tự động < 30 giây
  • Mở rộng App dễ dàng thêm node vào cluster
  • ETL/Crawler giai đoạn 2 chạy isolated trên BACKUP server
  • Không cần thay kiến trúc nền khi tích hợp ERP/IoT
Checklist trước Go-Live
  • Firewall rules reviewed & tested
  • TLS/SSL certificate cài đặt trên Nginx
  • DB Streaming Replication verified
  • Redis Sentinel failover tested
  • HAProxy VIP failover tested
  • Backup restore drill hoàn thành
  • Load test 160+ user đạt pass
  • Monitoring alert rules active
  • Runbook bàn giao cho ops team
  • Security hardening (SSH, fail2ban, SELinux)