This chapter will teach you everything about running applications in Azure, starting from absolute basics. We’ll explain what compute actually means, why different options exist, and how to choose and use them confidently.
Compute = The ability to run your codeThat’s it. When you write a program (a website, an app, a script), it needs to run SOMEWHERE. That “somewhere” needs:
CPU (Central Processing Unit): The brain that executes your code
Memory (RAM): Temporary storage while your code runs
Storage (Disk): Where your code and data are stored permanently
Compute is just a fancy tech word for “a computer that runs your code.”
Pros:✅ Free (you already own it)✅ Full control✅ Easy to testCons:❌ Only you can access it❌ Goes offline when you close laptop❌ Limited by your laptop's power❌ If laptop dies, app goes down
Option 2: Your Company’s Server (On-Premises)
Pros:✅ Your company controls it✅ Can handle more traffic than a laptop✅ Stays online 24/7 (if configured properly)Cons:❌ Expensive ($10,000+ upfront)❌ Takes weeks to set up❌ You manage everything (patches, hardware, backups)❌ Can't easily scale (bought 1 server, stuck with 1 server)
Option 3: Azure Cloud (What We’re Learning)
Pros:✅ No upfront cost (pay as you go)✅ Deploy in minutes✅ Scales automatically (1 server → 100 servers → 1 server)✅ Microsoft manages hardware✅ Available worldwideCons:❌ Monthly cost (but often cheaper than on-premises)❌ Need to learn Azure (that's why you're here!)
In simple terms, compute is the processing power that runs your applications—the CPU, memory, and resources that execute your code. Think of it as the “brain” of your application that processes requests, runs algorithms, and serves data to users.Azure offers multiple compute options, each designed for different scenarios. Choosing the right one impacts cost, performance, and operational overhead. This chapter will teach you what each service is, why you’d choose it, and how to use it effectively—from complete beginner to production-ready deployments.
Understanding the Compute-to-Application Relationship
Let’s make this concrete with a real example:Example: Building a Blog Website
Your Blog Application Needs:1. Web Server - Receives HTTP requests (user visits http://yourblog.com) - Sends back HTML pages - Compute needed: CPU to process requests, RAM to hold data2. Database - Stores your blog posts, comments, users - Compute needed: CPU to query data, RAM to cache queries3. File Storage - Stores images, videos you upload - Compute needed: Minimal (just storage, not much processing)Where does this run?- Without Azure: You set up a server in your closet- With Azure: You rent compute resources in Microsoft's datacenter
The Flow:
User visits yourblog.com ↓Request goes to Azure datacenter ↓Azure Compute (your rented "computer") receives request ↓Your application code runs on that compute ↓Code fetches blog post from database ↓Code generates HTML page ↓Compute sends HTML back to user ↓User sees your blogAll of this happens on Azure Compute in milliseconds.
You buy physical servers:- Pay upfront ($10,000+)- Takes weeks to arrive- Fixed capacity (can't scale)- You manage everything (OS, patches, hardware)- If server breaks, you're down until it's fixed
Cloud Computing (Azure):
You rent virtual servers:- Pay per hour/second (no upfront cost)- Deploy in minutes- Scale up/down instantly- Microsoft manages hardware- Automatic redundancy (if one fails, another takes over)
Virtual Machine = Renting an entire apartment (full control, more responsibility)
App Service = Renting a furnished room (less control, less responsibility, easier)
Azure Functions = Using a hotel room for one night (pay only when you use it)
[!TIP]
Jargon Alert: Compute
“Compute” is just a fancy word for “processing power” or “the ability to run code.” When someone says “compute resources,” they mean CPU, memory, and the servers that run your applications. Don’t let the word intimidate you—it’s just tech jargon for “the stuff that runs your code.”
[!WARNING]
Gotcha: Choosing the Wrong Compute Service
Many beginners choose VMs because they’re familiar, but VMs are often overkill. If you’re building a simple web app, use App Service. You’ll save time, money, and headaches. Only use VMs if you truly need full OS control.
These terms define how much Microsoft manages for you:
IaaS (Infrastructure as a Service)
PaaS (Platform as a Service)
Serverless (Function as a Service)
You manage: OS, runtime, applications, dataMicrosoft manages: Hardware, networking, datacenterExample: Virtual MachinesAnalogy: You rent a plot of land. You build the house, install plumbing, electricity—everything. The landlord just provides the land.When to use:
Need specific OS version (Windows Server 2012 R2)
Legacy applications that can’t run on PaaS
Full control over the environment
Compliance requirements (need to manage security patches yourself)
Trade-off: More control = More responsibility (you patch OS, manage security, handle failures)
You manage: Applications, dataMicrosoft manages: OS, runtime, patching, scalingExample: App Service, Azure SQL DatabaseAnalogy: You rent a furnished apartment. The landlord provides furniture, appliances, maintenance. You just bring your belongings and live there.When to use:
Modern web applications (Node.js, Python, .NET)
Want to focus on code, not infrastructure
Need automatic scaling
Faster time-to-market
Trade-off: Less control (can’t install custom software on OS) = Less responsibility (Microsoft handles patching, scaling)
You manage: Just your function codeMicrosoft manages: Everything else (scaling, infrastructure, OS)Example: Azure FunctionsAnalogy: You order food delivery. The restaurant handles cooking, packaging, delivery. You just eat when it arrives.When to use:
Stateless: Application doesn’t store session data on the server. Each request is independent.Example: A REST API that processes requests. If the server restarts, no data is lost because state is stored in a database.
# Stateless API@app.route('/api/users/<user_id>')def get_user(user_id): # No session data stored on server # Fetches from database each time return db.get_user(user_id)
Stateful: Application stores session data in memory. If server restarts, session is lost.Example: A game server that keeps player positions in memory.
# Stateful game serverplayer_positions = {} # Stored in memorydef update_position(player_id, x, y): player_positions[player_id] = (x, y) # Lost if server restarts
Why This Matters:
Stateless apps can scale horizontally easily (add more servers, load balance)
Stateful apps need sticky sessions or external state storage (Redis, database)
Best Practice: Make applications stateless. Store state in databases, Redis, or Cosmos DB.
[!TIP]
Jargon Alert: Stateless vs StatefulStateless: Like ordering at a fast-food restaurant. Each order is independent—the cashier doesn’t remember your last order. The app doesn’t store session data on the server.Stateful: Like a sit-down restaurant where the waiter remembers your preferences. The app stores session data in memory. If the server restarts, that memory is lost.
[!WARNING]
Gotcha: Stateful Applications Don’t Scale
If your app stores user sessions in memory, you can’t easily add more servers. User A’s session is on Server 1, but the load balancer might send them to Server 2, which doesn’t have their session. Always use external storage (database, Redis) for state.
Advantage: Can scale to hundreds/thousands of servers
Cost: More cost-effective at scale
Real-World Example:
Scenario: Your website gets 10x more trafficVertical Scaling:- Upgrade VM from 4 vCPU to 16 vCPU- Cost: $200/month → $800/month- Limitation: Can't go beyond 16 vCPUHorizontal Scaling:- Add 3 more VMs (4 total, each with 4 vCPU)- Cost: $200/month → $800/month (same cost, but 4x redundancy)- Advantage: If one VM fails, 3 others still serve traffic
Best Practice: Design for horizontal scaling from day one. Use load balancers, stateless applications, and autoscaling.
[!WARNING]
Gotcha: Spot VM Eviction
Spot VMs offer huge discounts (up to 90%), but Azure can take them back with only a 30-second warning. Never use them for production databases or critical APIs—only for stateless batch jobs that can fail and restart.
[!TIP]
Jargon Alert: SLA (Service Level Agreement)
Microsoft’s financial guarantee of uptime (e.g., 99.9%). If they miss it, you get a bill credit. Note: Single VMs often have a lower SLA than multiple VMs deployed in an Availability Set or Zone.
What is a Virtual Machine? A Virtual Machine (VM) is a software-based computer that runs on physical hardware. Think of it like this: Azure has massive physical servers in datacenters. They use virtualization technology to split one physical server into multiple “virtual” servers. Each VM gets its own CPU, RAM, and storage, isolated from other VMs.Why Use VMs?
Full Control: You have root/admin access. Install any software, configure anything.
Legacy Applications: Run old applications that require specific OS versions or configurations.
Custom Requirements: Need specific drivers, software, or configurations that PaaS doesn’t support.
Compliance: Some regulations require you to manage the OS yourself.
To a Principal Engineer, a “VM” isn’t just a virtual computer; it’s a slice of a massive, distributed system. Here is what’s happening behind the scenes.
Every physical host runs a custom version of Hyper-V.
It provides strict isolation between VMs. VM-A cannot see VM-B’s memory, even though they sit on the same physical chip.
It manages the vCPU scheduling. If you have a 2-vCPU VM, the hypervisor ensures you get your fair share of time on the physical CPU cores.
Real-World Analogy: The hypervisor is like an apartment building manager. Each tenant (VM) has their own apartment with walls between them. The manager allocates a fair share of shared resources (elevator time, water pressure, parking) but ensures no tenant can peek into another’s apartment. If one tenant makes too much noise (consumes too much CPU), the manager throttles them rather than letting them disturb everyone else.
3. Service Healing (Self-Correcting Infrastructure)
What happens if the physical server hosting your VM catches fire?
The Fabric Controller detects the heartbeats are missing.
It immediately marks that host as “failed”.
It finds a new, healthy physical host in the same cluster.
It “respawns” your VM on the new host and re-attaches your Managed Disks.
Your VM reboots automatically. This is why “Managed Disks” are critical—they live on the storage network, not the physical host, so they can be moved instantly.
[!IMPORTANT]
Pro Insight: Availability Sets vs. Zones
Availability Sets ensure your VMs are on different Racks (Power/Network) in the same building.
Availability Zones ensure your VMs are in different Buildings (miles apart).
Always use Availability Zones for production to survive a complete datacenter power failure.
When NOT to Use VMs:
Simple web applications (use App Service instead)
You just want to deploy code quickly (use PaaS)
You don’t want to manage OS patches (use PaaS)
[!WARNING]
Gotcha: VM Management Overhead
VMs require ongoing maintenance: OS patches, security updates, monitoring, backups. If you’re not prepared to manage this, use PaaS (App Service, Azure Functions). Many teams choose VMs thinking they’ll have “more control,” but end up spending 50% of their time on maintenance instead of building features.
[!TIP]
Jargon Alert: Virtual Machine (VM)
A VM is a software-based computer running on physical hardware. Think of it like this: Azure has massive physical servers. They use virtualization technology to split one physical server into multiple “virtual” servers. Each VM thinks it’s a real computer with its own CPU, RAM, and storage.
Before choosing a VM size, you need to understand what you’re buying:
vCPU (Virtual CPU)
Memory (RAM)
Storage (Disks)
Network
What it is: Processing power. More vCPUs = can handle more concurrent operations.Real-World Analogy: Like having more workers. 1 worker can handle 1 task at a time. 4 workers can handle 4 tasks simultaneously.How to Choose:
1-2 vCPU: Small websites, dev/test environments
4-8 vCPU: Medium web applications, small databases
16+ vCPU: Large databases, high-traffic applications, data processing
Common Mistake: Over-provisioning. If your app uses 20% CPU, you don’t need 16 vCPUs. Start small, monitor, then scale up.
[!WARNING]
Gotcha: Over-Provisioning Costs Money
Many beginners choose the biggest VM “to be safe.” A 16 vCPU VM costs 800/month.Ifyouonlyuse20640/month. Start with 2-4 vCPUs, monitor for a week, then scale up if needed. Azure makes it easy to resize VMs.
What it is: Temporary storage for running applications. Data in RAM is lost when VM restarts.Real-World Analogy: Like your desk space. More RAM = more applications can run simultaneously without slowing down.How to Choose:
2-4 GB: Small applications, static websites
8-16 GB: Web applications, APIs, small databases
32-64 GB: Large databases, in-memory caches (Redis), analytics
128+ GB: Enterprise databases (SQL Server), SAP HANA
Rule of Thumb:
Web applications: 2-4 GB per vCPU
Databases: 8-16 GB per vCPU
In-memory workloads: 16+ GB per vCPU
What it is: Permanent storage for OS, applications, and data. Data persists even when VM is stopped.Types:
OS Disk: Contains the operating system (Windows/Linux)
Data Disk: Additional storage for applications and data
Temp Disk: Temporary storage (ephemeral, lost on restart)
Real-World Analogy:
OS Disk = Your computer’s C: drive (Windows) or root partition (Linux)
Data Disk = External hard drive for your files
Temp Disk = RAM disk (fast but temporary)
How to Choose:
32-128 GB: OS Disk (Windows needs more, Linux needs less)
128 GB - 1 TB: Small applications, dev/test
1-4 TB: Production databases, file servers
4+ TB: Data warehouses, large file storage
What it is: Network bandwidth determines how fast data can flow in/out of the VM.Real-World Analogy: Like internet speed. 1 Gbps = can download 1 gigabit per second.How to Choose:
Low (1-2 Gbps): Small applications, dev/test
Medium (5-10 Gbps): Web applications, APIs
High (20+ Gbps): High-traffic applications, data processing
Note: Network speed is tied to VM size. Larger VMs get more bandwidth automatically.
B, D, DC, DS seriesBalanced CPU:Memory ratio (1:4)
Use cases:- Web servers- Small to medium databases- Development/test environments- Low to medium traffic appsExamples:- Standard_B2s: 2 vCPU, 4 GB RAM (Burstable)- Standard_D4s_v5: 4 vCPU, 16 GB RAM
B-series (Burstable):
Accumulate CPU credits when idle
Burst to 100% when needed
Cost-effective for variable workloads
Perfect for dev/test
Practical Tip: B-series VMs are the secret weapon for learning Azure. A B1s ($5/month) is included in the Azure free tier for 12 months and can run a small Linux web server comfortably. But never use B-series for production databases or latency-sensitive APIs — once you exhaust your CPU credits (which happens after ~30 minutes of sustained load), the VM throttles to 10% of its baseline CPU, making your app feel like it is running on a calculator.
F, FX seriesHigh CPU:Memory ratio (1:2)
Use cases:- Application servers- Batch processing- Analytics- Gaming serversExamples:- Standard_F8s_v2: 8 vCPU, 16 GB RAM- High CPU performance- Lower cost per vCPU
What is a Resource Group? Think of it as a folder that contains related resources. All resources in a group can be managed together (delete the group = delete all resources).
# Create resource groupaz group create \ --name rg-learn-vm \ --location eastus# What this does:# --name: Name of the resource group (must be unique in your subscription)# --location: Azure region where resources will be created# - eastus = East US (Virginia) - good for US East Coast# - westeurope = West Europe (Netherlands) - good for Europe# - southeastasia = Southeast Asia (Singapore) - good for Asia
Why eastus? It’s one of the cheapest regions and has all services available. For production, choose the region closest to your users.
What is a Virtual Network (VNet)? Think of it as your private network in Azure. VMs in the same VNet can communicate with each other privately (like computers on the same WiFi network).
# Create virtual networkaz network vnet create \ --resource-group rg-learn-vm \ --name vnet-learn \ --address-prefix 10.0.0.0/16 \ --subnet-name default \ --subnet-prefix 10.0.1.0/24# What this does:# --address-prefix 10.0.0.0/16: # - Defines the network range (10.0.0.0 to 10.0.255.255)# - /16 means first 16 bits are network, last 16 bits are hosts# - Can have up to 65,536 IP addresses (2^16)# --subnet-prefix 10.0.1.0/24:# - Subnet is a smaller network within the VNet# - /24 means first 24 bits are network, last 8 bits are hosts# - Can have up to 256 IP addresses (2^8)# - VMs will get IPs like 10.0.1.4, 10.0.1.5, etc.
Why 10.0.0.0/16? This is a private IP range (RFC 1918). It won’t conflict with public internet IPs. Common choices:
What is an NSG? A firewall that controls traffic to/from your VM. By default, Azure blocks all inbound traffic. You need to explicitly allow ports (like port 22 for SSH, port 3389 for RDP).
# Create NSGaz network nsg create \ --resource-group rg-learn-vm \ --name nsg-learn# Allow SSH (port 22) from anywhere# WARNING: In production, restrict to your IP only!az network nsg rule create \ --resource-group rg-learn-vm \ --nsg-name nsg-learn \ --name AllowSSH \ --priority 1000 \ --protocol Tcp \ --direction Inbound \ --source-address-prefixes '*' \ --source-port-ranges '*' \ --destination-address-prefixes '*' \ --destination-port-ranges 22 \ --access Allow# What this does:# --priority 1000: Lower number = higher priority (evaluated first)# --protocol Tcp: Allow TCP protocol (SSH uses TCP)# --direction Inbound: Rule applies to incoming traffic# --source-address-prefixes '*': Allow from any IP (NOT secure for production!)# --destination-port-ranges 22: Allow traffic to port 22 (SSH)# --access Allow: Allow this traffic (vs Deny)
Security Best Practice: Instead of '*', use your IP:
What is a NIC? The network card that connects your VM to the network. It connects the VM to the VNet, NSG, and Public IP.
# Create NICaz network nic create \ --resource-group rg-learn-vm \ --name nic-learn-vm \ --vnet-name vnet-learn \ --subnet default \ --network-security-group nsg-learn \ --public-ip-address pip-learn-vm# What this does:# --vnet-name: Connect to the VNet we created# --subnet: Connect to the subnet (default)# --network-security-group: Attach the NSG (firewall rules)# --public-ip-address: Attach the public IP (for internet access)
# Create VMaz vm create \ --resource-group rg-learn-vm \ --name vm-learn \ --location eastus \ --nics nic-learn-vm \ --image UbuntuLTS \ --size Standard_B2s \ --admin-username azureuser \ --generate-ssh-keys \ --authentication-type ssh# What this does:# --name: Name of the VM (must be unique in resource group)# --nics: Attach the network interface we created# --image UbuntuLTS: Use Ubuntu Linux (latest LTS version)# Alternatives: # - Win2019Datacenter (Windows Server 2019)# - RHEL (Red Hat Enterprise Linux)# - CentOS# --size Standard_B2s: VM size (2 vCPU, 4 GB RAM, Burstable)# --admin-username: Username for SSH login# --generate-ssh-keys: Automatically generate SSH key pair# - Creates ~/.ssh/id_rsa (private key) and ~/.ssh/id_rsa.pub (public key)# - Public key is added to VM for passwordless login# --authentication-type ssh: Use SSH keys (more secure than passwords)
# Get the public IP addressaz vm show \ --resource-group rg-learn-vm \ --name vm-learn \ --show-details \ --query publicIps \ --output tsv# Connect via SSH (replace with your IP)ssh azureuser@<PUBLIC_IP># Example:# ssh azureuser@20.123.45.67
First-time connection: You’ll see a message asking to verify the host. Type yes and press Enter.
Once connected, run these commands to verify everything works:
# Check OS versioncat /etc/os-release# Check CPU and memoryfree -hnproc# Check disk spacedf -h# Check networkip addr showping -c 3 8.8.8.8 # Test internet connectivity
Always delete resources when done to avoid charges:
# Delete the entire resource group (deletes all resources)az group delete \ --name rg-learn-vm \ --yes \ --no-wait# What this does:# --yes: Don't ask for confirmation# --no-wait: Don't wait for deletion to complete (runs in background)
Cost: A Standard_B2s VM costs ~$30/month if left running. Always delete when not in use!
[!WARNING]
Gotcha: VM Costs Add Up Quickly
A single VM might cost 30/month,butifyouforgettodelete10VMs,that′s300/month wasted. Always set up cost alerts and tag resources with “Owner” so you know who to contact. Use Azure Cost Management to find and delete unused resources.
[!TIP]
Jargon Alert: Deallocate vs StopStop (in OS): Shuts down the operating system, but Azure still reserves the hardware. You’re still charged for compute!Deallocate: Releases the hardware back to Azure. No compute charges, only storage charges. Always deallocate VMs when not in use.
[!INFO]
Aside: Azure Automation for Cost Savings
Use Azure Automation to automatically stop (deallocate) dev/test VMs at 6 PM and start them at 8 AM. Saves 60% on compute costs (no charges during nights/weekends).
When creating a VM, you make several important decisions:
Image (Operating System)
Size (VM Configuration)
Authentication
What it is: The OS and software pre-installed on the VM.Types:
Marketplace Images: Pre-configured OS (Ubuntu, Windows Server, RHEL)
Custom Images: Your own OS image (for consistent deployments)
Shared Image Gallery: Images shared across subscriptions
Common Choices:
UbuntuLTS: Ubuntu Linux (most popular for Linux)Win2019Datacenter: Windows Server 2019RHEL: Red Hat Enterprise Linux (enterprise)CentOS: Community version of RHEL
How to Choose:
Linux: Cheaper (no Windows license), better for web servers, APIs
Windows: Required for .NET Framework apps, Windows-specific software
What it is: The amount of CPU, RAM, and storage allocated to the VM.Naming Convention:
Standard_B2s│ │ ││ │ └─ Small (s) or Medium (m) - storage performance│ └─── Number of vCPUs (2)└─────────── Series (B = Burstable)
[!WARNING]
Gotcha: VMSS Rolling Upgrades Can Cause Downtime
If you don’t configure health probes correctly, a rolling upgrade might terminate healthy instances before new ones are ready. Always set minAvailable in PodDisruptionBudget (for AKS) or use instance protection (for VMSS) to prevent too many instances from being down at once.
[!TIP]
Jargon Alert: VM Scale Set (VMSS)
A VM Scale Set is a group of identical VMs that automatically scale based on demand. Think of it like a restaurant: when it’s busy (high CPU), you hire more waiters (add VMs). When it’s slow (low CPU), you send waiters home (remove VMs). All waiters are identical (same VM image), so they can handle any table (request).
What is App Service? App Service is Azure’s Platform-as-a-Service (PaaS) offering for hosting web applications. Think of it as a “managed web server” where you just deploy your code, and Microsoft handles everything else: OS updates, scaling, load balancing, SSL certificates, and more.Why Use App Service Instead of VMs?
Aspect
App Service
Virtual Machines
Setup Time
5 minutes
30+ minutes
OS Management
Microsoft handles
You manage
Scaling
Automatic (1-30 instances)
Manual or complex setup
SSL Certificates
Free (managed)
You install and renew
Deployment
Git push, ZIP, Docker
SSH, RDP, manual
Cost
0−700/month
30−2000+/month
Control
Limited (can’t install custom software)
Full control
Real-World Analogy:
VM: Like renting an empty apartment. You furnish it, maintain it, fix everything yourself.
App Service: Like staying in a hotel. Everything is provided, you just check in and use it.
When to Use App Service:
✅ Modern web applications (Node.js, Python, .NET, PHP, Java)
✅ REST APIs
✅ Mobile app backends
✅ You want to focus on code, not infrastructure
✅ Need automatic scaling
✅ Want zero-downtime deploymentsWhen NOT to Use App Service:
❌ Need to install custom software on the OS
❌ Need specific OS version (Windows Server 2012 R2)
❌ Legacy applications that require full VM control
❌ Need to run background services (use VMs or Container Instances)
When you scale an App Service to “3 instances”, what actually happens?
The Front End (Load Balancer): This is a shared layer provided by Microsoft. It receives all traffic to *.azurewebsites.net. It terminates SSL and routes the request to your specific worker.
The Worker (The Compute): This is your instance. This is where your code runs. If you have “3 instances”, you have 3 separate worker VMs (though you don’t manage them).
The File Server (Shared Storage): This is the most important “secret”. Your code and files don’t live on the worker’s local disk; they live on a Managed Remote File Share.
When you write a file to local storage in your code, it’s actually being written over the network to this share.
All 3 instances see the exact same files. This is why you don’t have to sync files between instances!
[!WARNING]
Performance Gotcha: The File System is a Network
Because the file system is remote, reading/writing thousands of small files (like a massive node_modules folder or a Local SQLite DB) can be slow.
Solution: Use WEBSITE_RUN_FROM_PACKAGE=1. This mounts your entire app as a read-only ZIP file, which is cached locally on the worker for blazing-fast startups and file access.
Key Concepts:
App Service Plan: The “hosting environment” that defines:
How much CPU/RAM you get
How many apps can run on it
What features are available (slots, VNet, etc.)
The cost
Web App: Your actual application running on the plan. You can have multiple web apps on one plan (to save money).
Deployment Slot: A separate instance of your app for testing. You can swap slots for zero-downtime deployments.
# Create Web Appaz webapp create \ --name mywebapp-learn-$(date +%s) \ --resource-group rg-learn-app \ --plan plan-learn \ --runtime "NODE|18-lts"# What this does:# --name: Name of web app (must be globally unique, like a domain)# - Format: <name>.azurewebsites.net# - Example: mywebapp-learn-1234567890.azurewebsites.net# --runtime: Programming language and version# Options:# - "NODE|18-lts" (Node.js 18 LTS)# - "PYTHON|3.11" (Python 3.11)# - "DOTNETCORE|7.0" (.NET 7)# - "PHP|8.2" (PHP 8.2)# - "JAVA|17" (Java 17)
Why the unique name? The web app name becomes part of the URL (mywebapp-learn-1234567890.azurewebsites.net). It must be globally unique across all Azure customers.
[!WARNING]
Gotcha: App Service Name Cannot Be Changed
Once you create an App Service, the name is permanent. You can’t rename it. If you need a different name, you must create a new app and migrate. Choose your name carefully!
[!TIP]
Jargon Alert: App Service Plan
An App Service Plan is like a “hosting package” that defines:
How much CPU/RAM you get
How many apps can run on it (you can host multiple apps on one plan)
What features are available (slots, VNet, autoscaling)
The cost
Think of it like a gym membership: the plan determines what equipment (features) you can use.
# Make a changeecho "console.log('New version!');" >> app.js# Commit and pushgit add app.jsgit commit -m "Add logging"git push# App Service automatically deploys (check logs to see it)
Result: Your app is accessible at https://www.example.com with a valid SSL certificate (green padlock in browser).
[!WARNING]
Gotcha: SSL Certificate Propagation
After adding a custom domain and SSL certificate, it can take 24-48 hours for DNS and SSL to fully propagate. Don’t panic if it doesn’t work immediately. Use dig or nslookup to verify DNS is pointing to your app.
[!INFO]
Aside: App Service Free Tier Limitations
The FREE tier is great for learning, but has serious limitations:
Apps “sleep” after 20 minutes of inactivity (takes 30+ seconds to wake up)
No custom domains
No SSL certificates
No deployment slots
No autoscaling
For production, use at least the Basic tier ($55/month). The FREE tier is only for learning/testing.
[!TIP]
Jargon Alert: Deployment Slot
A deployment slot is a separate instance of your app. Think of it like having two identical apartments—you can test new furniture (code) in one apartment before moving it to your main apartment. Slots enable zero-downtime deployments: deploy to staging slot, test it, then swap it with production instantly.
Free/Shared:❌ No custom SSL❌ No autoscaling❌ No deployment slots❌ No VNet integrationBasic:✅ Custom SSL❌ No autoscaling❌ No deployment slots❌ No VNet integrationStandard:✅ Custom SSL✅ Autoscaling (up to 10 instances)✅ Deployment slots (5)✅ VNet integration✅ Backup/restorePremium:✅ All Standard features✅ Autoscaling (up to 30 instances)✅ Deployment slots (20)✅ Better performance✅ Zone redundancyIsolated (ASE):✅ All Premium features✅ Fully isolated network✅ Internal load balancer✅ Compliance (PCI, HIPAA)
Q3: Design a scalable web application architecture
Architecture:Frontend:- Azure Front Door (global load balancing, WAF)- App Service (autoscale 2-20 instances)- Deployment slots (blue-green deployments)Backend:- VMSS or AKS (for microservices)- Autoscaling based on CPU/memory- Load balancer (internal)Data:- Azure SQL (zone-redundant)- Redis Cache (session management)- Blob Storage (static assets)Monitoring:- Application Insights (APM)- Log Analytics (centralized logs)- Autoscale based on custom metricsCI/CD:- GitHub Actions or Azure DevOps- Deploy to staging slot → test → swapCost Optimization:- Use B-series VMs for dev/test- Reserved Instances for production- Autoscale to match demand
Q4: How do you minimize VM costs?
Strategies:
1. Right-size VMs: - Monitor CPU/memory usage - Downsize underutilized VMs - Use Azure Advisor recommendations2. Use Reserved Instances: - 1-year: 30-50% savings - 3-year: 50-70% savings - For stable, long-running workloads3. Spot VMs: - Up to 90% discount - For fault-tolerant workloads (batch, testing)4. Stop VMs when not in use: - Dev/test: Stop nights and weekends - Use Azure Automation for scheduling5. Use B-series (Burstable): - For variable workloads - Accumulate credits when idle6. Azure Hybrid Benefit: - Use existing Windows licenses - Up to 40% savings7. Delete unused resources: - Unattached disks - Old snapshots - Orphaned NICs and public IPs8. Use autoscaling: - Scale down during low traffic - Scale up during high traffic
If you can’t SSH/RDP into your VM, follow this triage:
Resource Health: Check “Resource Health” in the portal. If it says “Platform Initiated”, Microsoft is currently moving your VM due to hardware failure. Wait 5 minutes.
Serial Console: Use the Serial Console tool. This gives you a direct command-line view of the VM’s boot process, even if the network is down.
Boot Diagnostics: Check the screenshot in “Boot Diagnostics”. See an “Update” screen or a “Blue Screen of Death” (BSOD)?
Redeploy: As a last resort, click Redeploy. This forces the Fabric Controller to move your VM to a completely different physical host.
Diagnose and Solve Problems: Use this built-in tool in the App Service portal. It’s surprisingly good at detecting things like “High Memory Usage” or “IP Restrictions”.
Log Stream: Check the Live Log Stream. Are you seeing “Out of Memory” (OOM) errors?
Kudu Console: Go to https://<appname>.scm.azurewebsites.net. This is the “Kudu” management site. You can browse files, check processes, and run commands directly on the worker.
Restart (Advanced): Don’t just restart the App. Restart the App Service Plan. This recycles all workers and can clear “Zombie Processes” that a simple app restart misses.
When would you choose App Service over AKS for a production web application, and when would that choice be wrong?
Strong Candidate Answer:
Choose App Service when: You have a standard web application with a team of fewer than 10 engineers, predictable traffic, and no need for sidecar containers. App Service P1v3 at $74/month gives you auto-scaling, deployment slots, managed SSL, and zero Kubernetes overhead. A team of 3 developers can deploy 10 times a day without a platform engineer.
Choose AKS when: You have 5+ microservices scaling independently, need service mesh for inter-service communication, or require multi-cloud portability with Helm charts. AKS wins for GPU workloads, custom admission controllers, and CronJobs.
Where App Service fails: 20+ microservices create management sprawl — each is a separate App Service plan with no built-in service discovery. At that scale, AKS with a single cluster is operationally simpler.
Where AKS is wrong: A startup with 2 engineers choosing AKS for one REST API is over-engineering. The Kubernetes learning curve costs 2-4 weeks. Minimum viable node pool (2x Standard_D2s_v5) is $140/month plus Container Registry, monitoring, and 20% of an engineer’s time on platform work.
Follow-up: The CTO insists on migrating everything from App Service to AKS because “Kubernetes is the future.” How do you push back?Quantify the cost: 3-6 months of engineering work, a platform engineer ($150K+/year), and 40-60% higher infrastructure costs. Present migration as risk-reward: what specific problem does AKS solve that App Service cannot? If the answer is “nothing right now,” adopt AKS for new services and leave working App Service workloads alone.
Your VMSS auto-scales at 70% CPU but new instances take 5 minutes to be healthy. Users see errors during scale-out. How do you fix this?
Strong Candidate Answer:
Root cause: New VMs must boot OS (60-90s), run script extensions to install dependencies (2-3 min), register with load balancer, and pass health probes. During this window, existing instances are overloaded.
Fix 1 — Lower threshold: Scale at 50% CPU instead of 70%. Triggers 3-5 minutes earlier, before saturation. Cost of 1-2 extra instances during normal traffic is negligible versus user errors.
Fix 2 — Custom VM images: Bake all dependencies into a Packer image. Boot time drops from 5 minutes to 60-90 seconds. This is the single biggest improvement.
Fix 3 — Predictive autoscaling: For predictable patterns (9 AM peaks), use scheduled scaling to pre-provision 15 minutes early.
Fix 4 — Consider containers: Container startup is 2-5 seconds vs 60-300 for VMs. AKS with Horizontal Pod Autoscaler eliminates the VM boot problem entirely.
Follow-up: After optimization, instances start in 90 seconds but existing ones still hit 95% CPU during the gap. What else?Deploy a minimum instance count at 120% of average traffic. The extra 20% costs $50/month but absorbs the burst. For mission-critical systems, combine pre-provisioned headroom with container-based scaling.
Compare IaaS, PaaS, and Serverless for a real-time pipeline ingesting 10 million events per day. Which do you choose?
Strong Candidate Answer:
IaaS (VMs + Kafka/Flink): Maximum control. 4x D8s_v5 VMs at 2,500/monthplusonefull−timeengineerat12K/month = $14,500/month total cost.
Serverless (Event Hub + Functions): Event Hub 500/month+Functions5/month = $550/month total. But windowed aggregations in Functions require external state management — added complexity.
My recommendation: PaaS for core pipeline. Stream Analytics SQL makes windowed aggregations trivial. Functions for ancillary processing (dead-letter handling, alerting). I would choose IaaS only if processing requires custom GPU models or volume exceeds 1 billion events/day where PaaS pricing becomes prohibitive.
Follow-up: At 1 billion events/day, does PaaS still make sense?At 1B events/day, PaaS costs ~10,500/month.ComparableIaaSis8,000/month in VMs but add $12,000/month engineering overhead. PaaS remains cheaper TCO until approximately 5B events/day, when dedicated infrastructure with a platform team becomes more economical.