Trang chủ/Chương 20

Chương 20: Architecture Patterns

Tổng Quan

10 architecture patterns phổ biến nhất trong kỳ thi SAA-C03. Mỗi pattern có sơ đồ kiến trúc, giải thích components, và exam keywords để nhận diện nhanh.


1. 🌐 Classic 3-Tier Web Application

Sơ Đồ

                         Internet Users
                              │
                              ▼
                        Amazon Route 53
                              │
                              ▼
                        Amazon CloudFront
                          (CDN Cache)
                              │
               ┌──────────────┴──────────────┐
               │         VPC (10.0.0.0/16)    │
               │                              │
               │    ┌──────────────────┐      │
               │    │  Application LB  │      │
               │    └────────┬─────────┘      │
               │             │                │
               │    ┌────────┴────────┐       │
               │    ▼                 ▼       │
               │  AZ-A              AZ-B      │
               │  ┌──────┐   ┌──────┐         │
               │  │ EC2  │   │ EC2  │ ← Web   │
               │  │(ASG) │   │(ASG) │   Tier   │
               │  └──┬───┘   └──┬───┘         │
               │     │          │              │
               │  ┌──▼───┐   ┌──▼───┐         │
               │  │ EC2  │   │ EC2  │ ← App   │
               │  │(ASG) │   │(ASG) │   Tier   │
               │  └──┬───┘   └──┬───┘         │
               │     └────┬─────┘              │
               │          │                    │
               │    ElastiCache (Redis)        │
               │          │                    │
               │  ┌───────┴──────────┐        │
               │  │  RDS Primary  ◄──► Standby│ ← DB Tier
               │  │    (AZ-A)        (AZ-B)   │   Multi-AZ
               │  └──────────────────┘        │
               └──────────────────────────────┘

Components & Vai trò

LayerComponentHAMục đích
EdgeCloudFrontGlobalCDN, cache static content
DNSRoute 53Multi-regionDNS, health checks
LBALBMulti-AZDistribute traffic, SSL
WebEC2 ASGMulti-AZWeb servers, auto scale
AppEC2 ASGMulti-AZBusiness logic, auto scale
CacheElastiCacheMulti-AZSession, query cache
DBRDS Multi-AZAuto failoverPersistent data

🎯 Exam Keywords

"web application" + "high availability" + "auto scaling" → Pattern này


2. ⚡ Serverless Web Application

Sơ Đồ

          Users → Route 53 → CloudFront
                                │
                 ┌──────────────┴──────────────┐
                 ▼                              ▼
           S3 Bucket                     API Gateway
         (Static Site)                    (REST API)
         HTML/CSS/JS                         │
                                    ┌────────┴────────┐
                                    ▼                  ▼
                              Lambda (Auth)      Lambda (Logic)
                                    │                  │
                                    ▼                  ▼
                               Cognito            DynamoDB
                           (User Auth)         (NoSQL Database)
                                                      │
                                                      ▼
                                              Lambda (Stream)
                                                      │
                                                      ▼
                                                 SES (Email)

So sánh Chi phí

Traditional (EC2)Serverless
Compute2 × t3.medium = $60/thángLambda (1M req) = $0.20
DatabaseRDS t3.small = $30/thángDynamoDB On-Demand = $1.25
LBALB = $22/thángAPI Gateway = $3.50
HostingEC2 servingS3 = $1
Tổng~$112/tháng (luôn chạy)~$6/tháng (pay per use)

🎯 Exam Keywords

"serverless" + "no operational overhead" + "pay per use" → Pattern này


3. 🐳 Microservices với Containers

Sơ Đồ

                    Application Load Balancer
                              │
              ┌───────────────┼───────────────┐
              ▼               ▼               ▼
       /api/users/*    /api/orders/*    /api/payment/*
       Target Group 1  Target Group 2  Target Group 3
              │               │               │
              ▼               ▼               ▼
       ECS Service 1   ECS Service 2   ECS Service 3
       (User)          (Order)         (Payment)
              │               │               │
       Fargate Tasks   Fargate Tasks   Fargate Tasks
              │               │               │
              ▼               ▼               ▼
            RDS           DynamoDB          SQS
          (Users)         (Orders)       → Payment Queue

Communication Patterns

PatternCơ chếUse case
SynchronousService A → ALB → Service BDirect call, cần response ngay
Async (Queue)Service A → SQS → Service BDecoupled, retry tự động
Event (Pub/Sub)Service A → SNS → Multiple ServicesFan-out, nhiều consumers

ECS vs EKS

Chọn ECS nếuChọn EKS nếu
AWS-native, đơn giảnĐã dùng Kubernetes
Tightly AWS integratedMulti-cloud strategy
Không có K8s expertiseComplex orchestration

🎯 Exam Keywords

"microservices" + "containers" + "independent scaling" → Pattern này


4. 🗄️ High Availability Database

RDS Multi-AZ

Application → RDS Endpoint (DNS auto-switch)
                    │
            ┌───────┴───────┐
            ▼               ▼
      ┌──────────┐   ┌──────────┐
      │ Primary  │◄─►│ Standby  │  Synchronous
      │  (AZ-A)  │   │  (AZ-B)  │  Replication
      │  Active  │   │ Passive  │
      └──────────┘   └──────────┘

Failover: 60-120 giây → DNS tự chuyển → App tự reconnect

Aurora Global Database

┌─── Primary Region (us-east-1) ──────────────┐
│  Writer ◄─► Read Replica × 2                │
│  Shared Storage (6 copies / 3 AZs)          │
└──────────────────┬───────────────────────────┘
                   │ < 1 giây replication
┌──────────────────▼───────────────────────────┐
│  Secondary Region (eu-west-1) — Read Only    │
│  Read Replicas × 3                           │
│  Promote to Primary < 1 phút (DR)           │
└──────────────────────────────────────────────┘

DynamoDB Global Tables

┌─ us-east-1 ─┐      ┌─ eu-west-1 ─┐
│  DynamoDB   │◄────►│  DynamoDB   │  Bi-directional
│  (R/W)      │      │  (R/W)      │  Active-Active
└──────┬──────┘      └──────┬──────┘
       │                     │
       └────────┬────────────┘
                ▼
       ┌─ ap-southeast-1 ─┐
       │  DynamoDB         │
       │  (R/W)            │
       └───────────────────┘

✅ < 1 giây replication  ✅ Write anywhere  ✅ Last-writer-wins

🎯 Exam Keywords

"automatic failover" → RDS Multi-AZ "cross-region DR, < 1 phút" → Aurora Global "multi-region active-active" → DynamoDB Global Tables


5. 🌉 Hybrid Cloud

┌─ On-Premises ───────────────────────────────────┐
│  Corporate Network ← → Customer Gateway        │
└──────────┬──────────────────────┬────────────────┘
           │ (Primary)            │ (Backup)
           │ Direct Connect       │ VPN over Internet
           │ 1/10 Gbps dedicated  │ IPSec tunnel
           │                      │
┌──────────▼──────────────────────▼────────────────┐
│                    AWS Cloud                      │
│  Virtual Private Gateway → Transit Gateway       │
│                                │                  │
│         ┌──────────────────────┼──────────┐      │
│         ▼          ▼           ▼          │      │
│      VPC Prod   VPC Dev    VPC Test       │      │
│                                           │      │
│  Storage Gateway → S3 → Glacier          │      │
└───────────────────────────────────────────────────┘
Direct ConnectVPNClient VPN
Bandwidth1/10/100 Gbps≤ 1.25 Gbps≤ 1 Gbps
LatencyLow, consistentVariableVariable
SetupWeeksMinutesMinutes
Cost$$$$$
Use caseProductionBackup/DRRemote workers

🎯 Exam Keywords

"dedicated connection" → Direct Connect "encrypted, quick setup" → VPN "hybrid storage" → Storage Gateway


6. 🌍 Multi-Region DR

Active-Passive

┌─ PRIMARY (us-east-1) — ACTIVE ─┐
│  Route 53 → ALB → EC2 ASG      │
│                  ↓               │
│              RDS Primary         │
└────────────────┬─────────────────┘
                 │ Cross-Region Replication
┌────────────────▼─────────────────┐
│ SECONDARY (eu-west-1) — PASSIVE  │
│  Route 53 (Failover)             │
│  ALB (Standby)                   │
│  EC2 ASG (Min=0)                 │
│  RDS Read Replica (→ promote)    │
│  RTO: 5-15 min | RPO: 5 min     │
└──────────────────────────────────┘

Active-Active

       Route 53 (Latency/Geo Routing)
              │                │
     ┌────────▼──────┐ ┌──────▼────────┐
     │  us-east-1    │ │  eu-west-1    │
     │  ⭐ ACTIVE    │ │  ⭐ ACTIVE    │
     │  CloudFront   │ │  CloudFront   │
     │  ALB → EC2    │ │  ALB → EC2    │
     │  DynamoDB  ◄──┼─┼──► DynamoDB  │ Global Tables
     │  S3 ◄─────────┼─┼────► S3      │ CRR
     └───────────────┘ └───────────────┘

🎯 Exam Keywords

"survive region failure" → Multi-Region "failover routing" → Active-Passive "latency-based routing" → Active-Active


7. 🔄 Event-Driven Architecture

SQS Pattern (Async Processing)

API Gateway → Lambda (Producer) → SQS Queue → Lambda (Consumer) → DynamoDB
                                      │
                                  DLQ (Failed)
✅ Decoupled  ✅ Auto retry  ✅ Independent scaling

SNS Fan-Out Pattern

                Event Source (S3, API)
                        │
                   SNS Topic
                   ┌────┼────┐
                   ▼    ▼    ▼
               SQS 1  SQS 2  Lambda
               ↓      ↓      ↓
            Service  Service  Email
              A        B      (SES)

Use case: Order → update inventory + create shipment + send email

EventBridge Complex Routing

Events (AWS, SaaS, Custom)
              │
        EventBridge Bus
              │
        Event Rules
     ┌────────┼────────┐
     ▼        ▼        ▼
  Lambda     SNS    Step Functions
(handler) (alert)  (workflow)

🎯 Exam Keywords

"decouple" + "message queue" → SQS "fan-out" + "pub/sub" → SNS "event routing" + "rules" → EventBridge "workflow orchestration" → Step Functions


8. 📊 Data Analytics Pipeline

┌─ Data Sources ──────────────────────────────────────────┐
│  IoT │ Web │ Mobile │ APIs │ RDS │ DynamoDB │ On-Prem  │
└──────┴─────┴────────┴──────┴─────┴──────────┴───┬──────┘
                                                   │
                              ┌─────────────────────┤
                              ▼                     ▼
                    Kinesis Data Streams     DataSync / DMS
                    (Real-time)             (Batch)
                              │                     │
              ┌───────────────┼──────────┐          │
              ▼               ▼          ▼          ▼
           Lambda        Firehose     Analytics     │
          (Process)      (Deliver)    (SQL)         │
              │               │                     │
              ▼               ▼                     │
          DynamoDB     ┌──────┴──────┐              │
         (Hot Data)    ▼             ▼              │
                   S3 (Data Lake) OpenSearch         │
                       │                            │
                       ▼                            │
                   AWS Glue (ETL + Catalog)         │
                       │                            │
              ┌────────┼────────┐                   │
              ▼        ▼        ▼                   │
           Athena   Redshift    EMR                 │
         (Query S3) (Data WH) (Hadoop)              │
              │        │        │                   │
              └────────┼────────┘                   │
                       ▼                            │
                  QuickSight (BI Dashboards)         │

Chọn Analytics Service

Nhu cầuService
Query S3 trực tiếp (serverless)Athena
Data warehouse, complex queriesRedshift
Big data processing (Hadoop/Spark)EMR
ETL + Data CatalogAWS Glue
BI dashboardsQuickSight
Real-time streamingKinesis Data Streams
Deliver streaming data to S3Kinesis Data Firehose

🎯 Exam Keywords

"query S3 with SQL" → Athena "data warehouse" → Redshift "ETL" → Glue "real-time streaming" → Kinesis Streams


9. 🔥 Disaster Recovery — 4 Strategies

Chi phí:  $ ─────────────────────────────────── $$$$
RTO/RPO:  Giờ ──────────────────────────────── Real-time

        Backup &     Pilot        Warm         Multi-Site
        Restore      Light        Standby      Active-Active
StrategyRTORPOMô tả
Backup & RestoreGiờ-NgàyGiờBackup → S3, restore khi cần
Pilot Light10s phútPhútCore DB always running, scale up khi DR
Warm StandbyPhútGiâyScaled-down version always running
Multi-SiteReal-timeNear-zeroFull production ở cả 2 regions

🎯 Exam Keywords

"lowest cost DR" → Backup & Restore "near-zero downtime" → Multi-Site "RPO minutes" → Pilot Light "RTO minutes" → Warm Standby


10. 🚀 Multi-Layer Caching

User Request
     │
┌────▼─────────────────────┐
│ Layer 1: CloudFront      │ ← Static content, TTL: hours-days
│ (600+ edge locations)    │   Cache hit ratio: 80-90%
└────┬─────────────────────┘
     │ Cache Miss
┌────▼─────────────────────┐
│ Layer 2: API Gateway     │ ← API responses, TTL: seconds-minutes
│ (Per-stage cache)        │   Cache hit ratio: 50-70%
└────┬─────────────────────┘
     │ Cache Miss
┌────▼─────────────────────┐
│ Layer 3: ElastiCache     │ ← DB queries, sessions, TTL: minutes
│ (Redis Multi-AZ)         │   Cache hit ratio: 70-90%
└────┬─────────────────────┘
     │ Cache Miss
┌────▼─────────────────────┐
│ Layer 4: DAX             │ ← DynamoDB cache, TTL: seconds
│ (Microsecond latency)    │   Cache hit ratio: 80-95%
└────┬─────────────────────┘
     │ Cache Miss
┌────▼─────────────────────┐
│ Database (Source of Truth)│ ← RDS / DynamoDB / Aurora
└──────────────────────────┘

Caching Strategies

StrategyFlowƯu điểmNhược điểm
Cache-AsideApp → Cache (miss?) → DB → Write cacheChỉ cache data cầnStale data có thể
Write-ThroughApp → Cache → DBCache luôn freshWrite latency cao
Write-BehindApp → Cache → (async) DBWrite nhanhRisk mất data

🎯 Exam Keywords

"reduce database load" → ElastiCache "cache DynamoDB" → DAX (microsecond) "cache static content globally" → CloudFront "cache API responses" → API Gateway caching


Exam Tips 💡

  1. Khi thấy "high availability web app" → nghĩ ngay Pattern 1 (3-Tier + Multi-AZ + ASG).
  2. "Serverless, no operational overhead" → Pattern 2 (Lambda + API GW + DynamoDB).
  3. "Decouple" → Pattern 7 (SQS/SNS/EventBridge).
  4. "Disaster recovery" → xác định RTO/RPO → chọn Pattern 9 tương ứng.
  5. "Reduce latency" → Pattern 10 (Multi-layer caching).
  6. "Migrate to cloud" → Pattern 5 (Hybrid) trước, rồi qua Cloud-native.

⬅️ Chương 19: Decision Trees & Keywords | Chương 21: Service Comparisons & Benchmarks ➡️