This guide provides practical approaches to reduce Azure infrastructure costs while maintaining security, reliability, and performance. Based on the Microsoft Azure Well-Architected Framework Cost Optimization pillar and real-world implementations.
Note on Pricing: Cost figures in this guide are approximate as of January 2025 in USD for the East US region. Azure pricing varies by region, currency, and billing agreements. Always verify current pricing at https://azure.microsoft.com/pricing/calculator/ before making budget decisions.
Azure costs follow a consumption-based model. The largest cost drivers are typically compute, storage, and networking. According to Microsoft’s Azure Cost Management best practices, organizations can reduce cloud spend by 30-50% through systematic optimization.
Reference: Azure Well-Architected Framework - Cost Optimization (https://learn.microsoft.com/en-us/azure/well-architected/cost-optimization/)
Different environments require different cost-performance trade-offs. This strategy is used by Azure MVPs and documented in Microsoft’s Cloud Adoption Framework.
Optimize for minimal costs while maintaining functionality for developers.
open Farmer
open Farmer.Builders
open Sql
// Minimal App Service Plan
let devAppPlan = servicePlan {
name "dev-app-plan"
sku WebApp.Sku.F1 // FREE tier
operating_system OS.Linux
}
let devWebApp = webApp {
name "dev-web-app"
link_to_service_plan devAppPlan
https_only
}
// Basic SQL Database
let devDatabase = sqlServer {
name "dev-sql-server"
admin_username "sqladmin"
add_databases [
sqlDb {
name "devdb"
sku Basic // ~$5/month
}
]
}
// Standard storage (LRS)
let devStorage = storageAccount {
name "devstorage"
sku Storage.Sku.Standard_LRS // Cheapest replication
}
let devEnvironment = arm {
location Location.EastUS
add_resources [
devAppPlan
devWebApp
devDatabase
devStorage
]
}
Development Cost: $30-80/month
| Component | SKU | Monthly Cost |
|---|---|---|
| App Service Plan | F1 (Free) | $0 |
| SQL Database | Basic | ~$5 |
| Storage Account | Standard LRS | ~$2 |
| Application Insights | 5GB free | $0-10 |
Balance cost and production similarity for pre-production testing.
// Shared App Service Plan
let stagingPlan = servicePlan {
name "staging-plan"
sku WebApp.Sku.B1 // Basic tier ~$13/month
operating_system OS.Linux
number_of_workers 1
}
let stagingDatabase = sqlServer {
name "staging-sql"
admin_username "sqladmin"
add_databases [
sqlDb {
name "stagingdb"
sku DtuSku.S1 // Standard tier ~$30/month
}
]
}
// Geo-redundant storage for testing failover
let stagingStorage = storageAccount {
name "stagingstorage"
sku Storage.Sku.Standard_GRS
}
let stagingEnvironment = arm {
location Location.EastUS
add_resources [
stagingPlan
stagingDatabase
stagingStorage
]
}
Staging Cost: $100-200/month
Optimized for reliability and performance with managed costs.
// Production App Service with scale-out
let prodPlan = servicePlan {
name "prod-plan"
sku WebApp.Sku.P1V3 // Premium v3 ~$100/month
number_of_workers 2
operating_system OS.Linux
}
let prodInsights = appInsights {
name "prod-insights"
}
let prodApp = webApp {
name "prod-web-app"
link_to_service_plan prodPlan
always_on
https_only
link_to_app_insights prodInsights.Name
}
// Production database with DTU-based pricing
let prodDatabase = sqlServer {
name "prod-sql"
admin_username "sqladmin"
add_databases [
sqlDb {
name "proddb"
sku DtuSku.S3 // 100 DTUs ~$150/month
}
]
// Geo-replication to West US for disaster recovery
geo_replicate ({
NameSuffix = "-replica"
Location = Location.WestUS
DbSku = Some DtuSku.S3
})
}
// Premium storage with geo-redundancy
let prodStorage = storageAccount {
name "prodstorage"
sku Storage.Sku.Premium_LRS
enable_data_lake true
}
let productionEnvironment = arm {
location Location.EastUS
add_resources [
prodPlan
prodInsights
prodApp
prodDatabase
prodStorage
]
}
Production Cost: $400-800/month
App Service Plans are often the largest compute cost. Strategic optimization can reduce costs by 40-60%.
According to Microsoft’s App Service best practices, most applications are over-provisioned by 30-50%.
// Cost comparison for App Service Plans
(*
F1 (Free): $0/month - Dev/test only, 60 min/day limit
B1 (Basic): ~$13/month - Small apps, no auto-scale
B2 (Basic): ~$25/month - Medium apps
S1 (Standard): ~$70/month - Production, auto-scale, 5 slots
P1V3 (Premium): ~$100/month - High performance, better CPU
P2V3 (Premium): ~$200/month - Scale-intensive workloads
*)
// Use consumption-based Functions for sporadic workloads
let scheduledJob = functions {
name "scheduled-processor"
// Consumption plan is the default
// Schedule configuration is done in the function app code, not infrastructure
}
Azure Reserved Instances provide 30-65% savings for 1-3 year commitments. Purchase through Azure portal, not Farmer deployment.
Savings Examples:
Reference: Azure Reserved Instances pricing (https://azure.microsoft.com/en-us/pricing/reserved-vm-instances/)
SQL Database offers multiple pricing models. Choosing the right model can reduce costs by 50-70%.
open Sql
// DTU Model: Simpler, bundled compute and storage
let dtuDatabase = sqlDb {
name "dtu-database"
sku DtuSku.S1 // 20 DTUs, ~$30/month
}
// vCore Model: More control, better for large databases
let vCoreDatabase = sqlDb {
name "vcore-database"
sku (GeneralPurpose Gen5_2) // 2 vCores, ~$500/month
}
// Serverless: Best for intermittent workloads
let serverlessDb = sqlDb {
name "serverless-db"
sku (GeneralPurpose(S_Gen5(0.5, 2.0))) // 0.5-2 vCores serverless
}
| Workload Type | Recommended SKU | Monthly Cost | Use Case |
|---|---|---|---|
| Development | Basic (5 DTUs) | ~$5 | Dev/test databases |
| Small Production | S1 (20 DTUs) | ~$30 | <100 users, simple queries |
| Medium Production | S3 (100 DTUs) | ~$150 | 100-1000 users, complex queries |
| Large Production | GP Gen5 4 vCore | ~$700 | >1000 users, always-on |
| Sporadic Use | Serverless 0.5-4 vCore | $90-300 | Intermittent access patterns |
Reference: Azure SQL Database pricing documentation (https://azure.microsoft.com/en-us/pricing/details/azure-sql-database/)
Use elastic pools when running multiple databases with varying load patterns. This is recommended by Microsoft for SaaS applications.
open Sql
let elasticPoolServer = sqlServer {
name "multi-tenant-server"
admin_username "pooladmin"
elastic_pool_name "shared-pool"
elastic_pool_sku PoolSku.Basic200
add_databases [
sqlDb { name "tenant-db-1" } // No SKU needed, uses pool
sqlDb { name "tenant-db-2" }
sqlDb { name "tenant-db-3" }
]
}
Cost Savings Example:
Storage costs accumulate over time. Lifecycle management and tier optimization are critical.
let optimizedStorage = storageAccount {
name "optimizedstorage"
sku Storage.Sku.Standard_LRS
add_lifecycle_rule "archive-old-data" [
Storage.DeleteAfter 365<Days>
Storage.CoolAfter 30<Days>
Storage.ArchiveAfter 90<Days>
] Storage.NoRuleFilters
}
Storage Tier Costs (per GB/month):
Cost Optimization Strategy:
// Development: Locally Redundant (LRS) - Cheapest
let devStorage = storageAccount {
name "devstorage"
sku Storage.Sku.Standard_LRS // 1x cost
}
// Production: Zone-Redundant (ZRS) - Balanced
let prodStorage = storageAccount {
name "prodstorage"
sku Storage.Sku.Standard_ZRS // 1.25x cost
}
// Critical: Geo-Redundant (GRS) - Most reliable
let criticalStorage = storageAccount {
name "criticalstorage"
sku Storage.Sku.Standard_GRS // 2x cost
}
Networking costs are often overlooked but can reach $500-2000/month in enterprise deployments.
open Farmer.VirtualNetworkGateway
// VPN Gateway: $27-650/month depending on SKU
let vpnGateway = gateway {
name "site-to-site-vpn"
vnet "my-vnet"
vpn_gateway_sku VpnGatewaySku.VpnGw1 // ~$140/month + data transfer
}
// ExpressRoute: $55-5,200/month for dedicated connection
let expressRouteGateway = gateway {
name "express-route-gw"
vnet "my-vnet"
er_gateway_sku ErGatewaySku.Standard // Configure capacity via portal
}
Cost Comparison: | Connection Type | Monthly Cost | Data Transfer | Use Case | |—————-|————–|—————|———-| | VPN Gateway Basic | ~$27 | $0.087/GB | Dev/test | | VPN Gateway VpnGw1 | ~$140 | $0.087/GB | Production | | ExpressRoute 50 Mbps | ~$55 | First 5TB free | Small enterprise | | ExpressRoute 1 Gbps | ~$700 | First 5TB free | Large enterprise |
For outbound connectivity from private subnets, compare NAT Gateway costs with individual public IPs.
NAT Gateway: $32.50/month + $0.045/GB processed Public IP: $3.50/month per IP (no data charges)
Use NAT Gateway when:
Application Insights charges per GB ingested. Uncontrolled logging can cost thousands per month.
let costOptimizedInsights = appInsights {
name "optimized-insights"
retention_days 30 // Default is 90 days
// Note: Sampling is configured in application code via ApplicationInsights SDK
// Not available as an infrastructure setting in Farmer
}
Typical Costs:
Cost Reduction Strategies:
Reference: Application Insights pricing (https://azure.microsoft.com/en-us/pricing/details/monitor/)
For global load balancing and routing, choose based on features needed.
open Farmer.TrafficManager
// Traffic Manager: DNS-based, $0.54/million queries
let trafficMgr = trafficManager {
name "global-traffic"
routing_method RoutingMethod.Performance
add_endpoints [
endpoint {
name "us-endpoint"
target_external "app-us.example.com" Location.EastUS
}
endpoint {
name "eu-endpoint"
target_external "app-eu.example.com" Location.NorthEurope
}
]
}
// Azure Front Door: Application layer, starts at ~$35/month
// Configure via Azure Portal - advanced CDN/WAF features
Cost Comparison: | Service | Base Cost | Data Transfer | Use Case | |———|———–|—————|———-| | Traffic Manager | $0.54/M queries | Standard egress | DNS routing only | | Azure Front Door | ~$35/month | $0.11/GB | WAF, caching, SSL offload |
Implement budget alerts to prevent cost overruns. This is critical for development accounts.
// Note: Azure Budgets created via portal or Azure CLI
// Example using Azure CLI:
(*
az consumption budget create \
--budget-name "dev-environment-budget" \
--amount 100 \
--resource-group dev-rg \
--time-grain Monthly \
--start-date 2025-01-01T00:00:00Z \
--end-date 2026-01-01T00:00:00Z
*)
Azure offers significant discounts for long-term commitments. According to Microsoft, customers save an average of 40-65%.
Reserved Instance Savings:
Purchase Strategy:
Reference: Azure Reservations documentation (https://learn.microsoft.com/en-us/azure/cost-management-billing/reservations/)
Implement these changes for immediate cost reduction:
Common mistakes that increase Azure costs unnecessarily:
Set realistic cost targets based on application complexity:
| Environment | Small App | Medium App | Large App |
|---|---|---|---|
| Development | $30-80 | $80-200 | $200-500 |
| Staging | $100-200 | $200-500 | $500-1000 |
| Production | $400-1000 | $1000-3000 | $3000-10000+ |
Microsoft Official Documentation:
Microsoft Learn Paths:
Community Resources:
Books:
This guide provides practical cost optimization strategies based on Microsoft’s best practices and real-world implementations. Always validate costs using the Azure Pricing Calculator before deployment.