Project 1: Highly Available Three-Tier Web Application on Azure with VM Scale Sets, Application Gateway and Azure SQL

Microsoft Azure Architect Technologies AZ 300 90 min min read Updated: Nov 17, 2026 Advanced
Project 1: Highly Available Three-Tier Web Application on Azure with VM Scale Sets, Application Gateway and Azure SQL
Advanced Topic 1 of 3

What We Build

text Internet | Application Gateway v2 + WAF (zones 1,2,3) subnet: appgw | VM Scale Set (Linux, nginx app) in zones 1,2,3 subnet: web <- Bastion for admin (subnet AzureBastionSubnet) | (private endpoint) Azure SQL Database (zone redundant) subnet: data (private endpoint) | Key Vault (secrets) + Log Analytics + Azure Monitor alerts
  • Region: Central India. Resource group: rg-3tier
  • No public IP on VMs or database. Only the gateway is public
  • Cost note: Application Gateway, Bastion and Premium SQL cost money. Delete the resource group when finished

Step 1: Network

bash az group create -n rg-3tier -l centralindia az network vnet create -g rg-3tier -n vnet-app --address-prefixes 10.20.0.0/16 --subnet-name appgw --subnet-prefixes 10.20.0.0/24 az network vnet subnet create -g rg-3tier --vnet-name vnet-app -n web --address-prefixes 10.20.1.0/24 az network vnet subnet create -g rg-3tier --vnet-name vnet-app -n data --address-prefixes 10.20.2.0/24 az network vnet subnet create -g rg-3tier --vnet-name vnet-app -n AzureBastionSubnet --address-prefixes 10.20.3.0/26 az network nsg create -g rg-3tier -n nsg-web az network nsg rule create -g rg-3tier --nsg-name nsg-web -n allow-appgw --priority 100 --source-address-prefixes 10.20.0.0/24 --destination-port-ranges 80 --access Allow --protocol Tcp az network vnet subnet update -g rg-3tier --vnet-name vnet-app -n web --network-security-group nsg-web

Step 2: Scale Set for the Web Tier

bash cat > cloud-init.yaml <<'EOF' #cloud-config package_update: true packages: [nginx] runcmd: - echo "Hello from $(hostname)" > /var/www/html/index.html EOF az vmss create -g rg-3tier -n vmss-web --image Ubuntu2204 --vm-sku Standard_B2s --instance-count 3 --zones 1 2 3 \ --vnet-name vnet-app --subnet web --lb "" --public-ip-address "" --custom-data cloud-init.yaml \ --admin-username azureuser --generate-ssh-keys --upgrade-policy-mode Automatic az monitor autoscale create -g rg-3tier --resource vmss-web --resource-type Microsoft.Compute/virtualMachineScaleSets --min-count 3 --max-count 9 --count 3 -n auto-web az monitor autoscale rule create -g rg-3tier --autoscale-name auto-web --condition "Percentage CPU > 70 avg 5m" --scale out 2 az monitor autoscale rule create -g rg-3tier --autoscale-name auto-web --condition "Percentage CPU < 30 avg 10m" --scale in 1

Step 3: Application Gateway with WAF

bash az network public-ip create -g rg-3tier -n pip-appgw --sku Standard --zone 1 2 3 az network application-gateway waf-policy create -g rg-3tier -n waf-policy --type OWASP --version 3.2 az network application-gateway create -g rg-3tier -n agw-web --sku WAF_v2 --capacity 2 --vnet-name vnet-app --subnet appgw \ --public-ip-address pip-appgw --waf-policy waf-policy --frontend-port 80 --http-settings-port 80 --http-settings-protocol Http --priority 100 --zones 1 2 3 # Add the scale set instances to the gateway backend pool (portal or: az vmss update ... --set with application gateway backend pool id) az network public-ip show -g rg-3tier -n pip-appgw --query ipAddress -o tsv

Open the IP in a browser. Refresh a few times. You should see different host names as traffic is balanced. Turn the WAF to Prevention mode after testing.

Step 4: Database with Private Endpoint

bash az sql server create -g rg-3tier -n sql3tier482 -l centralindia --enable-ad-only-auth --external-admin-principal-type User \ --external-admin-name admin@contoso.com --external-admin-sid <object-id> az sql db create -g rg-3tier -s sql3tier482 -n appdb --edition GeneralPurpose --family Gen5 --capacity 2 --zone-redundant true az network private-endpoint create -g rg-3tier -n pe-sql --vnet-name vnet-app --subnet data \ --private-connection-resource-id $(az sql server show -g rg-3tier -n sql3tier482 --query id -o tsv) --group-id sqlServer --connection-name sqlconn az network private-dns zone create -g rg-3tier -n privatelink.database.windows.net az network private-dns link vnet create -g rg-3tier -n link --zone-name privatelink.database.windows.net --virtual-network vnet-app --registration-enabled false az sql server update -g rg-3tier -n sql3tier482 --enable-public-network false
  • Give the scale set a managed identity and create a contained database user for it, so the app signs in without passwords

Step 5: Admin Access, Secrets and Monitoring

bash az network public-ip create -g rg-3tier -n pip-bastion --sku Standard az network bastion create -g rg-3tier -n bastion --vnet-name vnet-app --public-ip-address pip-bastion --sku Basic az keyvault create -g rg-3tier -n kv3tier482 --enable-rbac-authorization true az monitor log-analytics workspace create -g rg-3tier -n law3tier az monitor metrics alert create -g rg-3tier -n web-5xx --scopes $(az network application-gateway show -g rg-3tier -n agw-web --query id -o tsv) \ --condition "total FailedRequests > 20" --window-size 5m --evaluation-frequency 1m --severity 2

Step 6: Test Failure

  1. Stop one VM instance. The gateway health probe removes it and traffic continues
  2. Generate load (for example hey or Azure Load Testing) and watch autoscale add instances
  3. Trigger a SQL failover from the portal (zone redundancy) and confirm the app reconnects
  4. Try an attack string such as ?id=1 OR 1=1 and check WAF logs

Review With the Pillars

PillarWhat we did
Reliability3 zones, autoscale, zone-redundant SQL, health probes
SecurityWAF, no public VM or DB, private endpoint, Bastion, managed identity
CostSmall SKUs, autoscale in, delete after practice
OperationsAlerts, logs, move all commands into Bicep next
PerformanceScale out, add cache or CDN later

Clean Up

bash az group delete -n rg-3tier --yes --no-wait

Conclusion

You built a three-tier app across zones with a WAF gateway, autoscaling VM scale set, private zone-redundant SQL, Bastion, Key Vault and monitoring, then tested failure and reviewed it with the pillars.

Quick Summary: network; scale set; gateway; database; admin and monitoring; testing; review; cleanup.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators