Cost optimization không phải cắt giảm chi phí bằng mọi giá - mà là tối đa hóa business value trên mỗi đồng chi phí. Đây là pillar thường bị bỏ qua cho đến khi bill tháng gây shock.
# Xem right-sizing recommendations
az advisor recommendation list \
--category Cost \
--output table
# Xem chi tiết VM utilization
az monitor metrics list \
--resource /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Compute/virtualMachines/{vm} \
--metric "Percentage CPU" \
--interval PT1H \
--start-time 2026-04-03T00:00:00Z \
--end-time 2026-04-10T00:00:00Z \
--output table
Right-sizing Decision Tree
Azure Cost Management - Playbook
Step 1: Tagging Strategy
Mọi resource bắt buộc phải có tags để phân bổ chi phí.
bash
# Mandatory tags
az tag create --name environment
az tag create --name cost-center
az tag create --name owner
az tag create --name project
# Áp dụng tags cho resource group
az group update \
--name rg-ecommerce-prod \
--tags \
environment=production \
cost-center=CC-1234 \
owner=team-platform \
project=ecommerce
Tag policy - enforce bằng Azure Policy:
bash
# Require tag on resource groups
az policy assignment create \
--name require-cost-center-tag \
--policy "/providers/Microsoft.Authorization/policyDefinitions/96670d01-0a4d-4649-9c89-2d3abc0a5025" \
--params '{"tagName": {"value": "cost-center"}}' \
--scope /subscriptions/{sub-id}
# Tạo subscription loại Dev/Test (discount đáng kể)# Cần Visual Studio subscription# Discount: Windows VMs chỉ tính Linux price, PaaS giảm giá# Auto-shutdown cho dev VMs
az vm auto-shutdown \
--resource-group rg-dev \
--name vm-dev-01 \
--time 1900 \
--timezone "SE Asia Standard Time"
Dev/Test savings tiêu biểu:
Service
Production Price
Dev/Test Price
Savings
Windows VM (D4s_v5)
~$280/month
~$140/month
50%
Azure SQL (S3)
~$150/month
~$75/month
50%
App Service (P1v3)
~$100/month
~$50/month
50%
Serverless Cost Patterns
Azure Functions - Consumption Plan
Cost = Execution count x Price per execution
+ Execution time (GB-s) x Price per GB-s
Free grant per month:
- 1 million executions
- 400,000 GB-s
Scenario
Monthly Calls
Avg Duration
Memory
Estimated Cost
Light API
500K
200ms
256MB
~$0 (free tier)
Medium API
5M
500ms
512MB
~$15
Heavy processing
50M
1s
1GB
~$350
Comparison: App Service P1v3
Unlimited
N/A
8GB
~$100 fixed
Rule of thumb: Serverless rẻ hơn khi traffic < 3M requests/month hoặc rất bursty. Ổn định > 10M requests/month thì App Service / Container Apps rẻ hơn.
Storage Tier Optimization
Tier
Latency
Storage Cost (per GB/month)
Phù hợp
Premium
< 1ms
~$0.15
Database disks, real-time analytics
Hot
< 10ms
~$0.02
Frequently accessed data
Cool
< 10ms
~$0.01
Infrequent access (> 30 ngày)
Cold
< 10ms
~$0.005
Rare access (> 90 ngày)
Archive
Hours
~$0.001
Compliance, backup (> 180 ngày)
bash
# Set lifecycle management policy
az storage account management-policy create \
--account-name stmyapp \
--resource-group rg-app \
--policy @lifecycle-policy.json