</>Học Dev
Bài học

Tuần 10 - Ngày 2: Reserved Instances và Savings Plans Deep Dive

Tuần 10 – Ngày 2

Tuần 10 - Ngày 2: Reserved Instances và Savings Plans Deep Dive

Mục tiêu học tập

  • So sánh RI và Savings Plans
  • Hiểu Compute SP vs EC2 Instance SP
  • Áp dụng strategy mix RI/SP/On-Demand
  • Quản lý RI Marketplace

1. Reserved Instances (RI) Recap

Term

  • 1 hoặc 3 năm commitment
  • Discount lên đến 72%

Payment options

  • All Upfront (AURI): most discount
  • Partial Upfront (PURI): medium
  • No Upfront (NURI): least discount

Offering Class

  • Standard RI: locked attributes, can sell on Marketplace
  • Convertible RI: exchange to other instances (cùng giá trị trở lên), cannot sell

Scope

  • Regional RI (default): apply to any AZ in Region, no capacity reservation
  • Zonal RI: 1 AZ, capacity reservation included

Applies to

  • EC2, RDS, ElastiCache, OpenSearch, Redshift, DynamoDB

2. Savings Plans (SP) Recap

Commitment

  • $/hour for 1 or 3 years
  • e.g., commit $5/hour for 1 year → $$$$ savings

3 types

  • Compute Savings Plans: most flexible
  • EC2 Instance Savings Plans: limited to 1 family + region
  • SageMaker Savings Plans: for SageMaker

Applies to

  • Compute SP: EC2 (any family, region, OS, tenancy), Fargate, Lambda
  • EC2 Instance SP: 1 family, 1 region, any OS/tenancy/size
  • SageMaker SP: SageMaker training/inference

3. RI vs Savings Plans Comparison

FeatureReserved InstanceSavings Plans
CommitmentSpecific instance attributes$/hour spend
Applies toSpecific service (EC2/RDS/etc.)Compute (EC2+Fargate+Lambda) or EC2 family
FlexibilityConvertible RI = someCompute SP = highest
MarketplaceStandard RI can sellCannot sell
DiscountUp to 72%Up to 72%
Discount priorityRI applies firstSP applies after RI
Use caseSpecific predictable workloadFlexible compute commitment

Discount Application Order

1. AWS-generated discounts (free tier, promotional credits)
2. Reserved Instance discounts
3. Savings Plans discounts (after RI)
4. Remaining usage at On-Demand rate

4. Detailed: Compute Savings Plans

Flexibility

  • Switch EC2 family (m5 → c5 → r5)
  • Switch region
  • Switch OS (Linux → Windows)
  • Switch tenancy
  • Apply to Fargate, Lambda

Use case

  • Multi-region apps
  • Workload may evolve (migrate to Fargate, Lambda)
  • Most cost-conscious teams

Discount

  • Up to 66%

5. Detailed: EC2 Instance Savings Plans

Flexibility

  • Same family (e.g., m5) + same region
  • Switch size (m5.large → m5.xlarge)
  • Switch OS
  • Switch tenancy

Use case

  • Specific EC2 family standardization
  • Known region

Discount

  • Up to 72% (highest within SP)

6. Combining RI + SP + On-Demand

Best practice mix

Baseline 24/7 workload    → Reserved Instance 3y AURI (72% off)
Variable 80% of week      → Savings Plans 1y (66% off)
Peak hourly burst         → On-Demand (no commitment)
Background batch          → Spot (90% off)

Example calculation

  • Workload: 10 EC2 m5.large baseline + 5 peak during business hours
Strategy A: 100% On-Demand
- 15 instances × $0.10/hr × 730 hr = $1,095/month

Strategy B: Mix RI + On-Demand
- 10 RI 3y AURI: 10 × $0.04/hr × 730 = $292/month
- 5 On-Demand peak (8 hr/day, 22 days): 5 × $0.10 × 176 = $88
- TOTAL: $380/month (saving 65%)

7. RI Utilization Best Practices

Track utilization

  • Cost Explorer → Reserved Instance Utilization report
  • Target: 90%+
  • Below 50%: waste, consider modify

Improve utilization

  • Regional RI > Zonal RI (more flexible)
  • Convertible RI for changing workload
  • Standard RI for predictable

Sell on Marketplace (Standard RI only)

  • List remaining term
  • Buyers purchase shorter-term RIs
  • Recover cost when no longer needed

8. Savings Plans Utilization

Track

  • Cost Explorer → Savings Plans Utilization
  • Target: 90%+
  • Below 70%: review

Optimize

  • Right-size commitment (don't over-commit)
  • Use Compute SP for flexibility
  • Stack multiple SPs for granularity

Cannot resell

  • Avoid over-committing

9. Capacity Reservations (ODCR)

Định nghĩa

On-Demand Capacity Reservation = reserve capacity (instance available when needed) without commitment.

Đặc điểm

  • No discount on price (same as On-Demand)
  • Reserve capacity in specific AZ
  • Cancel anytime
  • Can combine với SP/RI for discount

Use case

  • Critical events (Black Friday, product launch)
  • DR scenario (ensure capacity for failover)
  • Stable workload needing AZ-specific capacity

vs Zonal RI

  • Zonal RI: capacity + discount + 1y/3y commitment
  • ODCR: capacity only, no commitment, can pair với SP/RI for discount

10. RI Pricing Math Example

Scenario: 1 m5.large 24/7 for 3 years (us-east-1, Linux)

Pricing$/hour3-year totalSaving
On-Demand$0.096$2,5240%
1-year No Upfront RI$0.067$1,76030%
1-year All Upfront RI$0.063$1,65035%
3-year No Upfront RI$0.042$1,10456%
3-year All Upfront RI$0.033$86766%
Compute SP 3y AURI$0.034$89564%
EC2 SP 3y AURI$0.030$78969%

Numbers approximate, verify on AWS Pricing.

11. Free Trial / Credits

Free Tier

  • 12 months free (e.g., 750 EC2 t2.micro hours)
  • Always-free services (Lambda 1M requests)

AWS Credits

  • Promotional credits (events, contests)
  • Apply to specific services or all
  • Expire after period

AWS Activate (startups)

  • Up to $100K credits for startup founders

12. Common Pricing Patterns

Pattern 1: Stable production

  • 100% RI 3-year AURI
  • Lowest cost for predictable workload

Pattern 2: Growing workload

  • Compute SP 1-year (re-evaluate yearly)
  • Some On-Demand for growth headroom

Pattern 3: Variable + batch

  • Baseline: SP for steady state
  • Peak: On-Demand
  • Batch: Spot

Pattern 4: Serverless

  • Lambda + Fargate covered by Compute SP
  • Pay-per-execution savings on top

Câu hỏi ôn tập

  1. Discount priority: RI applied trước hay sau SP?

    Xem đáp án

    RI applied trước, sau đó Savings Plans. Cả hai so sánh usage với committed resources: RI match exact instance type/AZ/OS configuration trước; Savings Plans flexible hơn và apply sau RI. Cả hai không thể "stack" trên cùng hour — RI committed hour không còn available cho SP. Unused RI/SP được "charged" dù không dùng — thiết kế để maximize utilization.

  2. Convertible RI cho phép đổi gì?

    Xem đáp án

    Convertible RI cho phép exchange sang RI khác có equal or greater value: đổi instance family (m5 → r5), OS (Linux → Windows), tenancy (shared → dedicated), region, size. Không thể exchange xuống giá trị thấp hơn (phải exchange nhiều RI nhỏ lấy một RI lớn). AWS apply blended pricing khi exchange. Discount thấp hơn Standard RI (~54% vs ~72%) để bù đắp flexibility.

  3. EC2 Instance SP khác Compute SP ở flexibility nào?

    Xem đáp án

    EC2 Instance SP: commit cho một instance family cụ thể trong một Region cụ thể (ví dụ: m5 in us-east-1) — có thể đổi size (m5.large → m5.4xlarge) và OS. Compute SP: flexible across instance family, size, Region, OS, và cả Lambda + Fargate. EC2 Instance SP discount cao hơn (~72%); Compute SP thấp hơn (~66%) nhưng flexible hơn nhiều. Compute SP phù hợp khi workload thay đổi.

  4. Standard RI có thể sell on Marketplace không?

    Xem đáp án

    — Standard RI có thể bán lại trên AWS Reserved Instance Marketplace khi không còn cần. Điều kiện: không phải All-Upfront mới mua < 30 ngày, phải là 1-year RI còn ít nhất 1 tháng, không phải Windows/RHEL/SUSE với dedicated tenancy. Convertible RI không bán được trên Marketplace — đây là trade-off của flexibility. Giá bán do người bán set, AWS take 12% fee.

  5. ODCR có discount không?

    Xem đáp án

    Không — On-Demand Capacity Reservation (ODCR) charge On-Demand rate kể cả khi không sử dụng. ODCR chỉ đảm bảo capacity available khi cần (không bị "capacity unavailable" errors). Để vừa có capacity reservation vừa discount, kết hợp với Zonal RI hoặc Savings Plans — chúng tự động apply discount lên ODCR matching. Hữu ích cho disaster recovery capacity reservation.

Bài tập thực hành

  • Vào Cost Explorer → RI Recommendations
  • So sánh cost 1 m5.xlarge với 5 pricing models trên Pricing Calculator
  • Check RI utilization của account (nếu có)
  • (Thử nghiệm) Mua 1 RI Zonal cho t3.micro 1-year No Upfront, observe sau
  • Setup Compute SP 1-year $1/hr commitment (cancellable trong 7 days nếu thử)

Tài liệu tham khảo chính thức


Tiếp theo: Spot Instance Strategies