Bỏ qua

02.EC2architectureResilience

🖥️ AWS EC2 Architecture Fundamentals: Hiểu sâu để master EC2 (Đủ thi cert & đi làm)


🎯 Tại sao hiểu EC2 Architecture quan trọng?

EC2 = Most Important AWS Service

  • Most frequently used AWS service
  • Most exam questions về EC2
  • Foundation cho nhiều AWS services khác
  • Real-world impact: Hiểu architecture → optimize cost & performance

PHẦN 1: EC2 High-Level Architecture

EC2 Instance = Virtual Machine

🖥️ EC2 Instance components:
├── Operating System (Linux/Windows)
├── Virtual CPU (vCPU)
├── Memory (RAM)
├── Storage
│   ├── Instance Store (temporary)
│   └── EBS Volumes (persistent)
├── Network Interface (ENI)
└── Additional hardware (GPU, etc.)

EC2 Hosts = Physical Servers

🏢 EC2 Host types:

Shared Hosts (Default):
  ✅ Multiple customers share same hardware
  ✅ Complete isolation between customers
  ✅ Pay per instance usage
  ✅ No hardware ownership

Dedicated Hosts:
  ✅ Entire host dedicated to your account
  ✅ You pay for whole host
  ✅ No sharing with other customers
  ✅ License compliance use cases

PHẦN 2: CRITICAL Concept - Availability Zone (AZ) Resilience

image

🚨 EXAM KILLER: EC2 is AZ-Resilient Service

❗ CRITICAL POINT (Remember this!):
  - EC2 hosts run in SINGLE AZ
  - AZ fails → EC2 instances in that AZ fail
  - Cannot move instances between AZs natively
  - All EC2 components tied to specific AZ

Visual Architecture

🏗️ Region: us-east-1
├── AZ-A (us-east-1a)
│   ├── EC2 Host 1
│   │   ├── Instance A1 (Customer 1)
│   │   └── Instance A2 (Customer 2)
│   ├── EBS Service (AZ-A)
│   └── Subnet A (10.0.1.0/24)
└── AZ-B (us-east-1b)
    ├── EC2 Host 2
    │   ├── Instance B1 (Customer 1)
    │   └── Instance B2 (Customer 3)
    ├── EBS Service (AZ-B)
    └── Subnet B (10.0.2.0/24)

PHẦN 3: EC2 Storage Architecture

Instance Store vs EBS

💾 Storage options:

Instance Store (Temporary):
  ✅ Physical storage on EC2 host
  ✅ Very high performance
  ❌ Lost when instance stopped/moved
  ❌ Not persistent
  Use case: Cache, temporary processing

EBS (Elastic Block Store):
  ✅ Persistent network storage
  ✅ Survives instance stop/start
  ✅ Can snapshot for backup
  ❌ Network-based (slight latency)
  Use case: OS, databases, persistent data

AZ Storage Isolation

🔒 Storage isolation rules:
  - EBS volume in AZ-A → only attach to instances in AZ-A
  - Cannot attach EBS from AZ-A to instance in AZ-B
  - Each AZ has separate EBS service
  - Instance Store tied to specific host in specific AZ

PHẦN 4: EC2 Networking Architecture

Elastic Network Interface (ENI)

🌐 ENI characteristics:
  - Primary ENI: Auto-created with instance
  - Secondary ENI: Can attach multiple
  - ENI belongs to specific subnet
  - Subnet belongs to specific AZ
  - Instance + ENI must be in same AZ

Networking Types

🔗 Two types of networking:

Storage Networking:
  - EBS communication
  - High bandwidth for data transfer

Data Networking:
  - Application traffic
  - User communication
  - Internet connectivity

PHẦN 5: Instance Lifecycle & Host Relationship

Instance-Host Relationship

🔄 Instance lifecycle:

Normal restart:
  ✅ Instance stays on same host
  ✅ All data preserved
  ✅ No disruption

Stop → Start:
  ⚠️ Instance may move to different host
  ⚠️ Same AZ, different physical server
  ⚠️ Instance Store data lost
  ✅ EBS data preserved

Host failure:
  🆘 Instance automatically moved to new host
  🆘 Instance Store data lost
  ✅ EBS data preserved

When Instance Moves Hosts

🚚 Instance moves when:
  1. Host hardware failure
  2. Host maintenance by AWS
  3. Instance stopped then started (not restart)

Always stays in same AZ!

PHẦN 6: Resource Sharing on Hosts

Host Resource Sharing

🏠 EC2 Host characteristics:
  - Multiple instances from different customers
  - Generally same instance type/generation per host
  - Complete isolation between customers
  - Shared CPU, memory, network resources
  - Fair share scheduling

Instance Type Grouping

📊 Host grouping logic:
  Host Type A: C5.large, C5.xlarge instances
  Host Type B: M5.large, M5.xlarge instances
  Host Type C: R5.large, R5.xlarge instances

  Same generation + family → same host type

PHẦN 7: When to Use EC2? (Cực quan trọng cho exam)

✅ EC2 Perfect For:

🎯 Ideal use cases:

Traditional OS + Application:
  - Legacy applications
  - Specific OS requirements
  - Vendor support needs

Long-running Compute:
  - 24/7 applications
  - Persistent services
  - Always-on requirements

Server-style Applications:
  - Web servers
  - Database servers
  - Application servers

Burst or Steady-state:
  - Variable workloads
  - Consistent processing
  - Predictable patterns

Monolithic Applications:
  - Single-tier applications
  - Tightly coupled components
  - Traditional architecture

Migration Scenarios:
  - Lift-and-shift migrations
  - Disaster recovery
  - Hybrid cloud setups

❌ Consider Alternatives When:

⚠️ EC2 might not be best for:

Short-running tasks:
  → Consider Lambda

Container workloads:
  → Consider ECS/EKS

Serverless requirements:
  → Consider Lambda/Fargate

Event-driven processing:
  → Consider Lambda + SQS

Microservices:
  → Consider ECS/EKS + containers

PHẦN 8: Architecture Implications for High Availability

Design for AZ Failure

🏗️ HA Architecture patterns:

Single AZ (Not HA):
  ❌ All instances in one AZ
  ❌ AZ failure = complete outage

Multi-AZ (HA):
  ✅ Instances across multiple AZs
  ✅ Load balancer distributes traffic
  ✅ AZ failure = partial capacity reduction
  ✅ Auto scaling compensates

Cross-AZ Considerations

⚡ Cross-AZ implications:

Network:
  - Cross-AZ traffic = small latency increase
  - Data transfer charges apply

Storage:
  - EBS replication across AZs (automatic)
  - Snapshots stored in S3 (multi-AZ)

Design:
  - Design assuming AZ can fail completely
  - Use AZ isolation as blast radius control

PHẦN 9: Checklist kiến thức thi cert & phỏng vấn

Core Architecture Points

  • [x] EC2 is AZ-resilient service (instances tied to specific AZ)
  • [x] Instances run on shared or dedicated hosts
  • [x] Instance Store = temporary, EBS = persistent
  • [x] ENI belongs to specific subnet in specific AZ
  • [x] Stop/start may move instance to different host (same AZ)

Storage Rules

  • [x] EBS volumes can only attach to instances in same AZ
  • [x] Instance Store lost when instance moves hosts
  • [x] Cannot cross AZ boundaries with storage or networking

Use Case Guidelines

  • [x] EC2 = default for traditional workloads
  • [x] Long-running, persistent applications
  • [x] OS-specific requirements
  • [x] Monolithic applications
  • [x] Migration scenarios

Câu hỏi exam killer

  1. "EC2 instance fails, what happens to Instance Store?" → Lost
  2. "Can attach EBS from AZ-A to instance in AZ-B?" → No
  3. "Instance stopped then started, stays on same host?" → Maybe not
  4. "AZ failure impact on EC2?" → All instances in that AZ affected
  5. "Best for short-running tasks: EC2 or Lambda?" → Lambda

PHẦN 10: Real-world Architecture Tips

Production Best Practices

🏭 Enterprise patterns:

Multi-AZ deployment:
  - Always deploy across multiple AZs
  - Use Auto Scaling Groups
  - Application Load Balancer for distribution

Storage strategy:
  - EBS for persistent data
  - Instance Store for temporary/cache
  - Regular EBS snapshots

Monitoring:
  - CloudWatch for metrics
  - Systems Manager for patching
  - AWS Config for compliance

Cost Optimization

💰 Cost optimization strategies:

Right-sizing:
  - Monitor CPU/memory utilization
  - Resize instances based on usage

Instance purchasing:
  - On-Demand for variable workloads
  - Reserved for steady-state
  - Spot for fault-tolerant workloads

Architecture optimization:
  - Consider serverless alternatives
  - Use managed services where possible

PHẦN 11: Tổng kết

  • EC2 = AZ-resilient virtual machines trên shared/dedicated hosts
  • Critical understanding: Everything tied to specific AZ
  • Design for AZ failure với multi-AZ architectures
  • EC2 = default choice cho traditional workloads
  • Instance Store vs EBS = temporary vs persistent storage
  • Stop/start ≠ restart về host placement

Ghi nhớ: EC2 architecture understanding là foundation cho tất cả advanced AWS concepts. Master AZ concept sẽ giúp bạn ace exam questions về availability, disaster recovery, và performance!

Next: Deep dive vào EC2 Instance Types, Sizing, và AWS Nitro System!