Skip to main content

09 - Cost Optimization

Tier selection, scaling strategies, and FinOps practices


💰 Tier Pricing Comparison

TierBase Cost/MonthScale UnitsBest For
Developer~$50No SLADev/Test
Basic~$150FixedLow traffic
Standard~$700IncludedMedium workloads
Premium~$2,800Add-onEnterprise
Basic v2~$170Add-onModerate + VNet
Standard v2~$280Add-onHigh + VNet

💡 Premium costs ~4x Standard but includes zone redundancy, multi-region, and VNet


📊 Cost Decision Tree


🎯 Right-Sizing Guidance

Traffic-Based Selection

Requests/SecondRecommended TierEstimated Cost
< 100Basic~$150/mo
100-500Standard~$700/mo
500-1,000Standard + Units~$1,000/mo
1,000-5,000Standard v2~$500/mo
> 5,000Premium~$3,500+/mo

Feature-Based Selection

RequirementMinimum Tier
Development/TestingDeveloper
Basic productionBasic
Caching, autoscaleStandard
VNet integrationBasic v2 / Premium
Multi-regionPremium
Zone redundancyPremium
Self-hosted gatewayPremium

💡 Cost Saving Strategies

1. Use Dev/Test Environments Wisely

// Use Developer tier for non-production
param environment string = 'dev'

var skuName = environment == 'prod' ? 'Premium' : 'Developer'
var skuCapacity = environment == 'prod' ? 2 : 1

resource apim 'Microsoft.ApiManagement/service@2023-05-01-preview' = {
name: 'apim-${environment}'
location: location
sku: {
name: skuName
capacity: skuCapacity
}
}

2. Schedule Scale-Down (Non-Production)

// Scale down after hours using automation
resource scaleDownSchedule 'Microsoft.Automation/automationAccounts/schedules@2023-11-01' = {
name: 'apim-scale-down'
parent: automationAccount
properties: {
frequency: 'Day'
startTime: '2024-01-01T19:00:00+01:00' // 7 PM
timeZone: 'W. Europe Standard Time'
}
}

3. Reserved Capacity (Premium)

CommitmentDiscount
1-year~30-40%
3-year~50-60%

💡 Contact Microsoft for reserved instance pricing on Premium tier

4. Optimize Caching

<!-- Cache responses to reduce backend calls (and costs) -->
<inbound>
<cache-lookup vary-by-developer="false"
vary-by-developer-groups="false"
downstream-caching-type="public"
caching-type="internal" />
</inbound>
<outbound>
<cache-store duration="3600" />
</outbound>

5. Rate Limiting to Control Costs

<!-- Prevent cost overruns from excessive usage -->
<rate-limit-by-key
calls="10000"
renewal-period="3600"
counter-key="@(context.Subscription.Id)" />

📉 Cost Monitoring

Azure Cost Management Query

// APIM costs by resource
AzureDiagnostics
| where ResourceProvider == "MICROSOFT.APIMANAGEMENT"
| summarize Cost = sum(CostUSD) by Resource, bin(TimeGenerated, 1d)
| render timechart

Budget Alerts

resource budget 'Microsoft.Consumption/budgets@2023-11-01' = {
name: 'apim-monthly-budget'
properties: {
amount: 5000
category: 'Cost'
timeGrain: 'Monthly'
timePeriod: {
startDate: '2024-01-01'
}
filter: {
dimensions: {
name: 'ResourceGroupName'
values: ['rg-apim-prod']
}
}
notifications: {
Actual_80: {
enabled: true
operator: 'GreaterThanOrEqualTo'
threshold: 80
contactEmails: ['platform-team@company.com']
}
Actual_100: {
enabled: true
operator: 'GreaterThanOrEqualTo'
threshold: 100
contactEmails: ['platform-team@company.com']
}
}
}
}

🏷️ Cost Allocation Tags

resource apim 'Microsoft.ApiManagement/service@2023-05-01-preview' = {
name: apimName
location: location
tags: {
CostCenter: 'IT-Platform'
Environment: environment
Project: 'DataMesh'
Owner: 'platform-team@company.com'
ChargebackProduct: 'API-Gateway'
}
// ... rest of config
}

Tag-Based Cost Report

TagPurpose
CostCenterDepartment chargeback
EnvironmentDev/Test/Prod split
ProjectProject allocation
OwnerContact for review
ChargebackProductProduct-level cost

📊 Cost Comparison: v1 vs v2 Tiers

FactorStandard (v1)Standard v2
Base price~$700/mo~$280/mo
Scale unitIncluded~$70/unit/mo
VNet supportNoYes
Zone redundancyNoOptional
Min deployment1 unit1 unit
Max scaleLimited10 units

When v2 is More Cost-Effective

Standard v1 = $700/month fixed

Standard v2 at different scales:
- 1 unit = $280 + $70 = $350/month ✅ Cheaper
- 3 units = $280 + $210 = $490/month ✅ Cheaper
- 5 units = $280 + $350 = $630/month ✅ Cheaper
- 6 units = $280 + $420 = $700/month ≈ Equal
- 7+ units = More expensive than v1

💡 v2 is more cost-effective up to ~6 scale units


🔄 Autoscaling for Cost Efficiency

Scale Based on Demand

resource autoscale 'Microsoft.Insights/autoscalesettings@2022-10-01' = {
name: 'apim-autoscale'
location: location
properties: {
enabled: true
targetResourceUri: apim.id
profiles: [
{
name: 'Business Hours'
capacity: {
default: '2'
minimum: '2'
maximum: '5'
}
recurrence: {
frequency: 'Week'
schedule: {
days: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
hours: [8]
minutes: [0]
timeZone: 'W. Europe Standard Time'
}
}
rules: [
{
metricTrigger: {
metricName: 'Capacity'
metricResourceUri: apim.id
timeGrain: 'PT1M'
statistic: 'Average'
timeWindow: 'PT10M'
timeAggregation: 'Average'
operator: 'GreaterThan'
threshold: 70
}
scaleAction: {
direction: 'Increase'
type: 'ChangeCount'
value: '1'
cooldown: 'PT20M'
}
}
]
}
{
name: 'Off Hours'
capacity: {
default: '1'
minimum: '1'
maximum: '2'
}
recurrence: {
frequency: 'Week'
schedule: {
days: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
hours: [19]
minutes: [0]
timeZone: 'W. Europe Standard Time'
}
}
rules: []
}
]
}
}

✅ Cost Optimization Checklist

Planning

  • Right tier selected for workload
  • v2 tiers evaluated for VNet needs
  • Reserved capacity evaluated (Premium)
  • Dev/Test uses Developer tier

Operations

  • Caching implemented
  • Rate limiting configured
  • Autoscaling enabled
  • Off-hours scaling configured

Monitoring

  • Cost tags applied
  • Budget alerts configured
  • Monthly cost reviews scheduled
  • Cost anomaly detection enabled

Optimization

  • Unused APIs removed
  • Cache hit rates monitored
  • Scale unit utilization tracked
  • Tier right-sizing reviewed quarterly

DocumentDescription
01-ArchitectureTier comparison
04-PoliciesCaching and rate limiting
06-MonitoringMetrics for optimization

Next: 10-Performance-Efficiency - Caching, autoscaling, and latency optimization

📖Learn