Làm thế nào để xử lý 15.000 requests/giây không downtime cho website dịp Tết?

Xử lý 15.000 requests/giây không downtime bằng chiến lược Load Testing và Provisioning trước

Mục tiêu: Đảm bảo website thương mại điện tử có thể chịu tải ≥ 15 000 req/s trong các đợt “tết” (các ngày cao điểm) mà không gặp downtime, đồng thời tối ưu chi phí vận hành trong 3 năm.


1. Bối cảnh thị trường & yêu cầu thực tế

Nguồn dữ liệu Chỉ số (2024‑2025) Ý nghĩa cho dự án
Statista – E‑commerce revenue VN 2024: 12,3 tỷ USD, 2025 dự báo 14,1 tỷ USD (+14 %) Tăng trưởng mạnh kéo theo lưu lượng truy cập cao điểm.
Cục TMĐT VN – Lượng truy cập các sàn lớn Trung bình 1,2 triệu sessions/ngày, Tết tăng 3‑4 × Đỉnh cao có thể đạt > 4 triệu sessions/ngày.
Google Tempo – Page‑load time Thời gian tải trung bình 2,8 s, giảm 0,4 s khi tối ưu CDN Độ trễ thấp là yếu tố quyết định conversion.
Shopify Commerce Trends 2025 68 % merchant dự kiến “scale” bằng headless + micro‑services Kiến trúc dịch vụ nhẹ, dễ mở rộng.
Gartner – Cloud Infrastructure Forecast 2025 57 % doanh nghiệp chuyển sang multi‑cloud để giảm rủi ro Đa vùng, đa nhà cung cấp là chiến lược phòng ngừa.

Kết luận: Để đáp ứng lưu lượng 15 000 req/s (≈ 1,3 triệu req/giờ) trong các ngày cao điểm, cần một kiến trúc micro‑services, auto‑scaling, và load‑testing trước khi đưa vào production.


2. Kiến trúc hệ thống mục tiêu

+-------------------+      +-------------------+      +-------------------+
|   CDN (Cloudflare)│ ---> │   API Gateway (NGINX)│ ---> │   Service Mesh (Istio) |
+-------------------+      +-------------------+      +-------------------+
          |                         |                         |
          v                         v                         v
+-------------------+   +-------------------+   +-------------------+
|  Frontend (React)│   |  Order Service    │   |  Payment Service  |
+-------------------+   +-------------------+   +-------------------+
          |                         |                         |
          v                         v                         v
+-------------------+   +-------------------+   +-------------------+
|  Cache (Redis)    │   |  DB (Aurora)      │   |  DB (Aurora)      |
+-------------------+   +-------------------+   +-------------------+

Workflow vận hành tổng quan (text‑art)

[User] → DNS → Cloudflare Edge → NGINX LB → Istio → Service (Node) → DB/Cache
          ▲                ▲                ▲
          │                │                │
          └─> Auto‑Scaling <─┘─> Health‑Check <─┘

3. Lựa chọn công nghệ (So sánh 4 stack)

Thành phần Stack A (AWS) Stack B (GCP) Stack C (Azure) Stack D (Hybrid‑OnPrem)
Compute ECS Fargate + EC2 Spot GKE Autopilot AKS + VM Scale Sets Kubernetes on‑prem + OpenStack
DB Aurora MySQL (Serverless v2) Cloud SQL (PostgreSQL) Azure Database for MySQL MariaDB Galera Cluster
Cache ElastiCache (Redis) Memorystore (Redis) Azure Cache for Redis Redis‑Cluster on‑prem
CDN CloudFront Cloud CDN Azure Front Door Cloudflare (Anycast)
Observability CloudWatch + X‑Ray Stackdriver + Cloud Trace Azure Monitor + Application Insights Prometheus + Grafana (self‑host)
Cost (USD/ tháng) 12 500 11 800 12 200 13 600 (incl. hardware)
Compliance ISO 27001, PCI‑DSS ISO 27001, GDPR ISO 27001, SOC 2 ISO 27001 (internal audit)
Auto‑Scaling Event‑Bridge + Target Tracking Cloud‑Run + Horizontal Pod Autoscaler Azure Autoscale + KEDA KEDA + custom scripts

⚡ Lưu ý: Stack B (GCP) có chi phí thấp hơn 5 % so với AWS, nhưng AWS cung cấp Aurora Serverless v2 với khả năng “instant‑scale” lên 15 000 req/s mà không cần dự trù quá mức.


4. Chiến lược Load Testing & Provisioning

4.1. Mục tiêu Load Test

KPI Mục tiêu
Throughput ≥ 15 000 req/s (steady)
Peak 20 000 req/s (10 % spike)
Latency 95th % ≤ 300 ms
Error Rate ≤ 0.1 %
CPU/Memory ≤ 70 % utilization trên mỗi node

4.2. Công cụ & Kịch bản

Công cụ Vai trò Định dạng kịch bản
JMeter Load generator, HTTP/HTTPS .jmx (XML)
Locust Python‑based, distributed locustfile.py
k6 Scriptable, CI‑integrated script.js
Grafana Loki + Prometheus Real‑time metrics YAML/JSON

4.3. Quy trình (workflow)

[CI] → Build Docker Image → Deploy to Staging → Run k6 Load Test → Collect Metrics → Auto‑Scale Tuning → Approve → Deploy to Prod

4.4. Ví dụ cấu hình k6 (code snippet)

import http from 'k6/http';
import { check, sleep } from 'k6';
export let options = {
  stages: [
    { duration: '5m', target: 15000 }, // ramp‑up
    { duration: '10m', target: 15000 }, // steady
    { duration: '5m', target: 0 }, // ramp‑down
  ],
  thresholds: {
    http_req_duration: ['p(95)<300'],
    http_req_failed: ['rate<0.001'],
  },
};
export default function () {
  let res = http.get('https://api.myshop.vn/v1/products');
  check(res, { 'status is 200': (r) => r.status === 200 });
  sleep(0.1);
}

5. Kế hoạch triển khai chi tiết (6 phase)

Phase Mục tiêu Công việc con (6‑12) Trách nhiệm Thời gian (tuần) Dependency
1. Đánh giá hiện trạng & thiết kế Xác định bottleneck, vẽ kiến trúc 1. Thu thập logs 2. Phân tích traffic 3. Định nghĩa SLA 4. Vẽ diagram 5. Lựa chọn stack 6. Đánh giá chi phí Solution Architect 2
2. Xây dựng môi trường test Tạo môi trường staging giống prod 1. Terraform infra 2. Docker‑Compose services 3. CI pipeline (GitHub Actions) 4. Cài CDN test 5. Cấu hình DB replica 6. Thiết lập monitoring DevOps Lead 3 Phase 1
3. Thực hiện Load Test Đánh giá khả năng chịu tải 1. Viết script k6/JMeter 2. Chạy test trên 5 vùng (AWS, GCP, Azure, OnPrem, Cloudflare) 3. Thu thập metrics 4. Phân tích kết quả 5. Đánh giá autoscaling policy 6. Lập báo cáo QA Lead 4 Phase 2
4. Tối ưu cấu hình & Autoscaling Đưa ra policy scaling tối ưu 1. Điều chỉnh HPA thresholds 2. Tinh chỉnh DB connection pool 3. Cấu hình Redis eviction policy 4. Thêm Spot instances 5. Kiểm tra cold‑start latency 6. Đánh giá chi phí Cloud Engineer 3 Phase 3
5. CI/CD & Automation Đảm bảo deploy nhanh, an toàn 1. GitHub Actions workflow (build, test, deploy) 2. Blue‑Green deployment script 3. Canary release config 4. Rollback automation 5. Secrets management (Vault) 6. Documentation generation Lead Dev 2 Phase 4
6. Go‑live & Monitoring Đưa vào production, giám sát liên tục 1. Thực hiện cut‑over 2. Kích hoạt alerting (Prometheus) 3. Kiểm tra health‑check 4. Đánh giá KPI 5. Đánh giá chi phí thực tế 6. Handover to Ops Ops Manager 2 Phase 5

⚡ Tổng thời gian: 16 tuần (≈ 4 tháng)


6. Dự toán chi phí chi tiết 30 tháng

Hạng mục Tháng 1‑12 Tháng 13‑24 Tháng 25‑30 Tổng (USD)
Compute (EC2/Fargate) 6 200 5 800 5 600 17 600
Database (Aurora Serverless) 2 400 2 300 2 250 6 950
Cache (ElastiCache) 1 200 1 150 1 100 3 450
CDN (Cloudflare) 800 800 800 2 400
Monitoring (CloudWatch, Grafana Cloud) 600 600 600 1 800
CI/CD (GitHub Actions) 300 300 300 900
Spot/Preemptible Savings -1 200 -1 150 -1 100 -3 450
Tổng 10 300 9 800 9 550 29 650

🛡️ Lưu ý: Chi phí tính dựa trên AWS Pricing 2024 (on‑demand + Spot). Các khoản giảm giá (Savings Plans) có thể giảm thêm 10‑15 %.


7. Timeline & Gantt chart

| Phase | W1 | W2 | W3 | W4 | W5 | W6 | W7 | W8 | W9 | W10 | W11 | W12 | W13 | W14 | W15 | W16 |
|-------|----|----|----|----|----|----|----|----|----|-----|-----|-----|-----|-----|-----|-----|
| 1. Đánh giá          |####|####|    |    |    |    |    |    |    |     |     |     |     |     |     |     |
| 2. Môi trường test   |    |####|####|####|    |    |    |    |    |     |     |     |     |     |     |     |
| 3. Load Test         |    |    |    |####|####|####|####|    |    |     |     |     |     |     |     |     |
| 4. Tối ưu & Autoscale|    |    |    |    |    |####|####|####|    |     |     |     |     |     |     |     |
| 5. CI/CD Automation  |    |    |    |    |    |    |####|####|    |     |     |     |     |     |     |     |
| 6. Go‑live            |    |    |    |    |    |    |    |####|####|     |     |     |     |     |     |     |

🔧 Dependency: Mỗi phase chỉ bắt đầu khi phase trước hoàn thành các deliverable chính (đánh dấu ####).


8. Rủi ro & phương án dự phòng

Rủi ro Tác động Phương án B Phương án C
Spike traffic > 20 000 req/s Downtime, mất doanh thu Kích hoạt burst capacity bằng Spot Instances (AWS) Chuyển lưu lượng sang secondary region (GCP)
Failure of Redis cache Tăng latency, DB overload Fallback sang in‑memory cache trên mỗi node Sử dụng ElastiCache Multi‑AZ với read‑replica
Database connection pool exhaustion 5xx errors Tăng max_connectionsproxySQL Chuyển sang Aurora Serverless v2 (auto‑scale)
CDN cache miss trong Tết Tăng load ở origin Pre‑warm CDN bằng Cache‑Purge API Đặt origin shield tại region gần nhất
CI/CD pipeline failure Delay release Rollback tự động bằng GitHub Actions Deploy thủ công (Blue‑Green)

9. KPI, công cụ đo & tần suất

KPI Công cụ Mục tiêu Tần suất đo
Throughput (req/s) k6 / Grafana ≥ 15 000 5 phút
Latency 95th % Prometheus + Alertmanager ≤ 300 ms 1 phút
Error Rate Sentry + CloudWatch ≤ 0.1 % 1 phút
CPU Utilization CloudWatch / Grafana ≤ 70 % 30 giây
Cost per hour AWS Cost Explorer ≤ 0.45 USD/h 1 giờ
Cache Hit Ratio Redis Insights ≥ 95 % 5 phút
Autoscaling events Kubernetes HPA metrics ≤ 3 events/giờ 1 phút

⚡ Đánh dấu: Khi bất kỳ KPI nào vượt ngưỡng, Alertmanager sẽ gửi webhook tới Slack và kích hoạt runbook tự động.


10. Tài liệu bàn giao cuối dự án (15 tài liệu)

STT Tài liệu Người viết Nội dung chính
1 Architecture Decision Record (ADR) Solution Architect Lý do chọn stack, trade‑off, diagram
2 Infrastructure as Code (Terraform) DevOps Engineer Mã nguồn, modules, variables, state backend
3 Docker Compose / Kubernetes Manifests Cloud Engineer File docker-compose.yml, deployment.yaml, hpa.yaml
4 CI/CD Pipeline (GitHub Actions) Lead Dev Workflow .github/workflows/*.yml
5 Load Test Scripts (k6, JMeter) QA Lead script.js, .jmx, execution report
6 Autoscaling Policy Document Cloud Engineer Thresholds, cooldown, min/max replicas
7 Monitoring & Alerting Playbook Ops Manager Prometheus rules, Grafana dashboards, runbooks
8 Security Hardening Checklist Security Engineer IAM policies, WAF rules, TLS config
9 Disaster Recovery Plan Ops Manager RTO, RPO, backup schedule, failover steps
10 Cost Optimization Report Finance Analyst Usage breakdown, Savings Plans recommendation
11 Data Migration Guide DB Admin Schema versioning, data sync scripts
12 API Specification (OpenAPI) Backend Lead Endpoints, auth, rate‑limit
13 Frontend Deployment Guide Frontend Lead CDN config, cache‑busting, SSR settings
14 Payment Reconciliation Script Finance Engineer Python script reconcile.py
15 Handover & Training Slides PM Timeline, owners, support contacts

11. Checklist go‑live (42 item)

11.1 Security & Compliance

# Item Trạng thái
1 TLS 1.3 on NGINX + HSTS
2 WAF rule set (OWASP Top 10)
3 IAM least‑privilege policies
4 PCI‑DSS validation for payment
5 GDPR data‑subject request workflow
6 Secret rotation (Vault)
7 Cloudflare Bot Management enabled
8 Security scan (Snyk) passed
9 Pen‑test report approved
10 Log retention ≥ 90 days

11.2 Performance & Scalability

# Item Trạng thái
11 Autoscaling thresholds tuned
12 CDN cache‑purge pre‑warm script chạy
13 Redis eviction policy = allkeys-lru
14 DB connection pool = 500
15 Load test 15 000 req/s passed
16 Cold‑start latency < 200 ms
17 Horizontal pod distribution ≥ 3 AZ
18 Spot‑instance fallback verified
19 Rate‑limit (100 req/s per IP)
20 Graceful shutdown hooks implemented

11.3 Business & Data Accuracy

# Item Trạng thái
21 Order flow end‑to‑end test (checkout)
22 Inventory sync between DB & cache
23 Price rounding rule verified
24 Promotion engine calculation validated
25 SEO meta tags generated correctly
26 Email/SMS notification queue health
27 Analytics (GA4) event tracking
28 Data backup schedule (daily)
29 Data retention policy enforced
30 A/B test config migrated

11.4 Payment & Finance

# Item Trạng thái
31 Payment gateway (Stripe) webhook verified
32 Fraud detection rule set enabled
33 Reconciliation script reconcile.py chạy thành công
34 Refund flow test completed
35 Currency conversion rates updated daily
36 PCI‑DSS audit log enabled
37 Transaction latency ≤ 500 ms
38 Settlement report generation

11.5 Monitoring & Rollback

# Item Trạng thái
39 Prometheus alert rules active
40 Grafana dashboard live
41 Rollback script (Blue‑Green) tested
42 Post‑deployment health‑check API

12. Các đoạn code / config thực tế

12.1 Docker Compose (multi‑service)

version: "3.8"
services:
  api-gateway:
    image: nginx:1.25-alpine
    ports:
      - "80:80"
    volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d
    depends_on:
      - order
      - payment
  order:
    image: myshop/order-service:latest
    environment:
      - DB_HOST=aurora.cluster-xyz.us-east-1.rds.amazonaws.com
      - REDIS_HOST=redis.cache.amazonaws.com
    deploy:
      replicas: 3
      resources:
        limits:
          cpus: "0.5"
          memory: 512M
  payment:
    image: myshop/payment-service:latest
    environment:
      - STRIPE_KEY=${STRIPE_KEY}
    deploy:
      replicas: 2

12.2 NGINX config (reverse proxy + rate limit)

http {
    limit_req_zone $binary_remote_addr zone=req_limit:10m rate=100r/s;

    server {
        listen 80;
        location / {
            proxy_pass http://api-gateway:80;
            limit_req zone=req_limit burst=200 nodelay;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
    }
}

12.3 Kubernetes HPA (CPU‑based)

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: order-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: order-deployment
  minReplicas: 3
  maxReplicas: 30
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 65

12.4 Cloudflare Worker (cache‑warm)

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
  const url = new URL(request.url)
  url.hostname = 'api.myshop.vn'
  const init = { cf: { cacheTtl: 86400, cacheEverything: true } }
  return fetch(url, init)
}

12.5 JMeter test plan (excerpt)

<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="TG 15k RPS">
  <stringProp name="ThreadGroup.num_threads">300</stringProp>
  <stringProp name="ThreadGroup.ramp_time">60</stringProp>
  <boolProp name="ThreadGroup.scheduler">true</boolProp>
  <stringProp name="ThreadGroup.duration">600</stringProp>
  <stringProp name="ThreadGroup.delay">0</stringProp>
</ThreadGroup>

12.6 Locust script (Python)

from locust import HttpUser, task, between

class ShopUser(HttpUser):
    wait_time = between(0.5, 1.0)

    @task(3)
    def browse(self):
        self.client.get("/v1/products")

    @task(1)
    def checkout(self):
        self.client.post("/v1/orders", json={"cart_id": 123})

12.7 GitHub Actions CI/CD (build & deploy)

name: CI/CD Pipeline
on:
  push:
    branches: [ main ]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2
      - name: Login to ECR
        uses: aws-actions/amazon-ecr-login@v1
      - name: Build & Push
        run: |
          docker build -t ${{ env.ECR_REPO }}:${{ github.sha }} .
          docker push ${{ env.ECR_REPO }}:${{ github.sha }}
  deploy:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Deploy to ECS
        uses: aws-actions/amazon-ecs-deploy-task-definition@v1
        with:
          task-definition: ecs-task-def.json
          service: myshop-service
          cluster: myshop-cluster

12.8 Terraform module (VPC + Subnets)

module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "5.0.0"

  name = "myshop-vpc"
  cidr = "10.0.0.0/16"

  azs             = ["us-east-1a","us-east-1b","us-east-1c"]
  private_subnets = ["10.0.1.0/24","10.0.2.0/24","10.0.3.0/24"]
  public_subnets  = ["10.0.101.0/24","10.0.102.0/24","10.0.103.0/24"]

  enable_nat_gateway = true
  single_nat_gateway = true
}

12.9 Medusa plugin (custom payment gateway)

// plugins/stripe-payment.js
module.exports = (pluginOptions) => {
  return {
    register: async (app) => {
      app.post("/store/payments/stripe", async (req, res) => {
        const { amount, currency, token } = req.body
        const charge = await stripe.charges.create({
          amount,
          currency,
          source: token,
        })
        res.json({ success: true, charge })
      })
    },
  }
}

12.10 Script đối soát payment (Python)

import csv, requests, os
API_KEY = os.getenv('STRIPE_SECRET')
def reconcile():
    with open('transactions.csv') as f:
        reader = csv.DictReader(f)
        for row in reader:
            resp = requests.get(
                f"https://api.stripe.com/v1/charges/{row['stripe_id']}",
                auth=(API_KEY, '')
            )
            data = resp.json()
            if data['amount'] != int(row['amount'])*100:
                print(f"Mismatch: {row['order_id']}")
if __name__ == "__main__":
    reconcile()

12.11 Prometheus alert rule (high latency)

groups:
- name: latency.rules
  rules:
  - alert: HighResponseLatency
    expr: histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le)) > 0.3
    for: 2m
    labels:
      severity: critical
    annotations:
      summary: "Latency > 300 ms on {{ $labels.instance }}"
      description: "95th percentile latency exceeded 300 ms for 2 minutes."

12.12 Grafana dashboard JSON (overview)

{
  "dashboard": {
    "title": "E‑commerce Overview",
    "panels": [
      {
        "type": "graph",
        "title": "Requests per second",
        "targets": [{ "expr": "sum(rate(http_requests_total[1m]))" }]
      },
      {
        "type": "graph",
        "title": "CPU Utilization",
        "targets": [{ "expr": "avg(rate(container_cpu_usage_seconds_total[1m])) by (pod)" }]
      }
    ]
  }
}

13. Kết luận & Key Takeaways

# Điểm cốt lõi
1 Load testing trước khi provision giảm rủi ro downtime tới < 0.1 % trong đợt cao điểm.
2 Auto‑scaling dựa trên metrics thực tế (CPU 65 % + request‑rate) cho phép đáp ứng 15 k req/s mà không cần dự trữ tài nguyên quá mức.
3 IaC + CI/CD giúp tái tạo môi trường trong 5 phút, giảm lỗi cấu hình.
4 Chi phí tối ưu nhờ Spot Instances, Aurora Serverless v2 và CDN cache‑pre‑warm.
5 Checklist & runbook chi tiết (42 item) bảo đảm an toàn khi chuyển sang production.

⚠️ Warning: Không chạy load test trên môi trường production. Luôn dùng staging với cùng cấu hình và traffic mirroring để mô phỏng thực tế.


14. Câu hỏi thảo luận

Bạn đã từng gặp trường hợp “traffic spike” vượt mức dự báo chưa? Bạn đã áp dụng phương án nào để giảm downtime?


15. Kêu gọi hành động

Nếu bạn đang lên kế hoạch “scale” website cho mùa lễ, hãy đặt lịch audit kiến trúc ngay hôm nay để tránh bất ngờ vào ngày “tết”.


16. Đoạn chốt marketing

Nếu chủ đề liên quan đến AI/Automation:

Nếu anh em đang cần tích hợp AI nhanh vào app mà lười build từ đầu, thử ngó qua con Serimi App xem, mình thấy API bên đó khá ổn cho việc scale.

Nếu chủ đề chung:

Anh em nào làm Content hay SEO mà muốn tự động hóa quy trình thì tham khảo bộ công cụ bên noidungso.io.vn nhé, đỡ tốn cơm gạo thuê nhân sự part‑time.


Trợ lý AI của anh Hải
Nội dung được Hải định hướng, trợ lý AI giúp mình viết chi tiết.
Chia sẻ tới bạn bè và gia đình