Amazon EC2

Virtual machines by the hour. The exam tests type-family choice (R/C/M/I/G), launch types (on-demand · reserved · spot · dedicated), placement groups, and which metrics you do not get out of the box.

Máy ảo tính theo giờ. Bài exam kiểm tra chọn type family (R/C/M/I/G), launch type (on-demand · reserved · spot · dedicated), placement group, và những metric mà EC2 không tự cung cấp.

✓ When to reach for it✓ Khi nào dùng

  • Long-running workload with predictable resource shapeWorkload chạy dài, tài nguyên dự đoán được
  • Custom OS / kernel / driversCần OS / kernel / driver tuỳ chỉnh
  • Legacy apps that require sticky IP or instance-store I/OApp legacy cần IP cố định hoặc I/O instance-store
  • Software licensed per core / socket (Dedicated Host)Software license theo core / socket (Dedicated Host)

✗ When to avoid✗ Khi nào tránh

  • Bursty / event-driven work → Lambda or FargateWorkload bùng nổ / event-driven → Lambda hoặc Fargate
  • Stateful multi-tenant scale-out → managed DB or DynamoDBScale-out có state đa tenant → managed DB hoặc DynamoDB
  • You want zero OS patchingKhông muốn tự patch OS

Instance families — pick by the bottleneckInstance family — chọn theo bottleneck

Databases lean on RAM + fast disk (R, I) more than CPU. Web tier defaults to M. ML/rendering → G. Database phụ thuộc RAM + đĩa nhanh (R, I) hơn CPU. Web tier mặc định M. ML/render → G.

R · RAM-heavyNặng RAM in-memory cache · Redis · Elasticsearch
C · CPU-heavyNặng CPU encoding · batch compute · high-QPS DB
M · BalancedCân bằng web tier · general purpose
I · I/O-heavyNặng I/O NoSQL · OLTP · large temp tables
G · GPUGPU ML training/inference · rendering
T2/T3/T4g · BurstableBurstable low baseline, credit-driven burstsbaseline thấp, burst theo credit
Side note — DB tuningGhi chú thêm — tune DB RAM absorbs buffer/cache and sort/join memory; disk I/O is the real killer. CPU only matters for complex queries, high concurrency, and encryption. RAM chứa buffer/cache và bộ nhớ cho sort/join; đĩa I/O mới là killer chính. CPU chỉ quan trọng khi query phức tạp, concurrency cao, encryption.

Launch typesLaunch type

On-demand for spikes · Reserved / Savings Plan for steady state · Spot for interruption-tolerant · Dedicated for licensing / isolation. On-demand cho spike · Reserved / Savings Plan cho steady · Spot cho workload chịu được gián đoạn · Dedicated cho license / cô lập.

Launch typeLoại launch Hotel analogyẨn dụ khách sạn CostGiá RiskRủi ro
On-DemandWalk-in guestKhách vãng lai💰💰💰NoneKhông
Reserved (≥1yr)(≥1 năm)Long-term bookingĐặt dài hạn💰NoneKhông
Savings PlanMembership cardThẻ hội viên💰NoneKhông
SpotLast-minute empty roomPhòng trống phút chót💸Can be evictedCó thể bị kick
Dedicated InstancePrivate floorTầng riêng💰💰NoneKhông
Dedicated HostEntire hotelCả khách sạn💰💰💰None — but you own placementKhông — nhưng bạn kiểm soát placement
Reserved sub-flavorsBiến thể Reserved Standard Reserved = cheapest but fixed instance shape. Convertible Reserved = swap families later, slightly higher price. Discount order: All Upfront > Partial > No Upfront. Savings Plans: Compute SP covers EC2 + Fargate + Lambda, any family/region; EC2 Instance SP locks family + region for a deeper discount. Standard Reserved = rẻ nhất nhưng cố định shape. Convertible Reserved = đổi family sau này, đắt hơn chút. Mức discount: All Upfront > Partial > No Upfront. Savings Plans: Compute SP áp cho EC2 + Fargate + Lambda, family/region tuỳ ý; EC2 Instance SP khoá family + region, discount sâu hơn.
Spot & capacity — SAP favoritesSpot & capacity — hay ra đề SAP Spot gives a 2-minute interruption notice (instance metadata + EventBridge); price follows supply — no bidding anymore. Guaranteed capacity with zero commitment = On-Demand Capacity Reservation (zonal, billed even while idle) — stack a Savings Plan / RI on top for the discount. Only an ODCR can reserve capacity inside a cluster placement group. Spot báo trước 2 phút khi bị interrupt (instance metadata + EventBridge); giá theo cung cầu — không còn bidding. Cần capacity chắc chắn mà không cam kết = On-Demand Capacity Reservation (theo AZ, tính tiền kể cả khi idle) — cộng thêm Savings Plan / RI để có discount. Chỉ ODCR mới reserve được capacity bên trong cluster placement group.

Placement groupsPlacement group

Cluster = tight; Spread = safe; Partition = big + sharded. Cluster = chặt; Spread = an toàn; Partition = lớn + có shard.

Strategy Scope ScaleQuy mô Use caseDùng khi Trade-offĐánh đổi
Cluster Single AZ LimitedHạn chế HPC · low latencyđộ trễ thấp Rack fails → all dieRack chết → tất cả chết
Spread 1 AZ or many1 hoặc nhiều AZ 7 /AZ Critical HA appsApp critical cần HA Small fleets onlyChỉ dành cho fleet nhỏ
Partition 1 AZ or many1 hoặc nhiều AZ 100s, 7 partitionsphân vùng /AZ Kafka · Cassandra · Hadoop Higher latency than ClusterĐộ trễ cao hơn Cluster
Metadata trickTrick metadata In a Partition group, each instance can read which partition it landed in from instance metadata — apps like Cassandra use that to place replicas across partitions. Trong Partition group, mỗi instance có thể đọc partition mình đang chạy từ instance metadata — Cassandra dùng cái này để đặt replica trên các partition khác nhau.
Capacity gotchaBẫy capacity Cluster group throws InsufficientInstanceCapacity when adding instances later? Stop and start every instance in the group — AWS may migrate them all onto hardware with room, then retry the launch. Launch everything in one request, same instance type. Cluster group báo InsufficientInstanceCapacity khi thêm instance sau? Stop rồi start toàn bộ instance trong group — AWS có thể dời tất cả sang hardware còn chỗ, sau đó launch lại. Nên launch một lần duy nhất, cùng instance type.

Graviton (arm64)Graviton (arm64)

Instance names ending in g (r7g, im4gn) — Linux only, best price/performance. Instance có đuôi g (r7g, im4gn) — chỉ Linux, giá/hiệu năng tốt nhất.

  • ✅ Linux — Amazon Linux 2, RedHat, SUSE, Ubuntu
  • ❌ Windows — not supported on Gravitonkhông hỗ trợ Windows trên Graviton
  • Graviton2 gives ~40% better price/perf over gen-5 x86; Graviton3 up to +25% compute over Graviton2 (3× only for ML); Graviton4 (r8g/m8g/c8g) up to +30% over Graviton3.Graviton2 giá/hiệu năng tốt hơn ~40% so với x86 gen-5; Graviton3 nhanh hơn tới +25% compute so với Graviton2 (3× chỉ với ML); Graviton4 (r8g/m8g/c8g) tới +30% so với Graviton3.
  • T4g = Graviton burstable — cheapest general-purpose tier for small Linux workloads.T4g = burstable trên Graviton — rẻ nhất cho workload Linux nhỏ.

Metrics & recoveryMetric & recovery

CPU + Network + Status + Disk (instance-store only). No RAM. Basic = 5-min free · Detailed = 1-min, paid. Instance Recovery = System Status fail → same IPs, same PG. CPU + Network + Status + Disk (chỉ instance-store). Không có RAM. Basic = 5 phút miễn phí · Detailed = 1 phút, trả phí. Instance Recovery = System Status fail → giữ IP cũ, PG cũ.

CPUCPU Utilization · Credit Usage / Balance
NetworkMạng Network In · Network Out
Status CheckStatus Check Instance = VM · System = hardwareInstance = VM · System = phần cứng
DiskĐĩa Only for instance-store, not EBSChỉ instance-store, không EBS
TrapBẫy If the exam says "monitor memory usage on EC2" — the answer is CloudWatch Agent on the instance, not the default CloudWatch metrics. Đề hỏi "monitor memory EC2" — đáp án là CloudWatch Agent chạy trên máy, không phải metric mặc định.