Deploying Web Apps with Azure App Services: A Complete Beginner's Guide

1.43K 0 0 0 0

📘 Chapter 3: Configuration, Scaling, and Performance Optimization

🔍 Overview

Once your web application is deployed to Azure App Services, the next step is to ensure it's configured properly, scales effectively, and runs with optimal performance. This chapter provides a comprehensive walkthrough of advanced configuration options, environment setup, autoscaling rules, diagnostic tools, and real-world performance best practices.


🛠️ 1. App Settings and Configuration Management

Azure App Services allows you to define environment-specific configurations directly through the App Settings section, similar to environment variables in traditional development.

🔹 Why Use App Settings?

  • Securely store app-level environment variables
  • Override application configurations per environment (e.g., dev, staging, prod)
  • Inject secrets (via Azure Key Vault integration)

Add App Settings via CLI

bash

 

az webapp config appsettings set \

  --name mywebapp \

  --resource-group MyResourceGroup \

  --settings NODE_ENV=production API_URL=https://api.example.com

🧪 Best Practices

  • Use separate resource groups for staging and production
  • Use descriptive keys (e.g., APP_MODE, CONN_STR_DATABASE)
  • Avoid hardcoding secrets—integrate with Key Vault

🔐 2. Integrating Azure Key Vault for Secrets

To protect sensitive values like API keys or DB passwords:

  1. Store Secret in Key Vault

bash

 

az keyvault secret set --vault-name MyVault \

  --name DB-Password --value "MySecurePass123"

  1. Reference in App Setting

Use the following format:

less

 

@Microsoft.KeyVault(SecretUri=https://MyVault.vault.azure.net/secrets/DB-Password/)

🔒 App must have permission to access the Key Vault.


️ 3. Platform and Runtime Configuration

You can control aspects like:

  • .NET version or Node.js runtime
  • 32-bit or 64-bit architecture
  • Startup commands for custom entry points
  • Application stack auto-updates

Example: Set .NET Core Version via CLI

bash

 

az webapp config set \

  --name mywebapp \

  --resource-group MyResourceGroup \

  --net-framework-version v6.0


🚀 4. Scaling App Services: Manual vs Autoscale

Azure App Services supports both vertical and horizontal scaling.

🔹 Vertical Scaling

Upgrade your App Service Plan for more CPU/RAM:

bash

 

az appservice plan update \

  --name MyPlan \

  --resource-group MyResourceGroup \

  --sku P1V2

🔹 Horizontal Scaling

Add more instances manually or automatically.

Manual Scaling:

bash

 

az webapp scale \

  --name mywebapp \

  --resource-group MyResourceGroup \

  --number-of-workers 3

Enable Autoscale:

Via Portal → App Service → Scale Out → Custom Autoscale

Rule Trigger

Scale Action

CPU > 70% (5 min)

Add 1 instance

CPU < 30% (10 min)

Remove 1 instance

📈 Scaling Guidelines

Scenario

Recommendation

Sudden traffic spikes

Enable autoscaling with CPU/memory rules

Predictable workloads

Use scheduled scaling

High-availability systems

Use minimum 2+ instances across zones


📊 5. Performance Optimization Tips

Performance depends on proper code, configuration, and service usage.

Enable Compression

bash

 

az webapp config set \

  --resource-group MyResourceGroup \

  --name mywebapp \

  --http20-enabled true \

  --web-sockets-enabled true

Enable Gzip from Azure Portal → Configuration → General Settings.


Use Persistent Storage (if needed)

  • Use Azure Blob Storage for media or file uploads
  • Avoid using local filesystem unless for temporary data

Keep App Warm

To avoid cold start delays:

  • Use Always On (Standard Tier+)
  • Send scheduled pings to the endpoint

bash

 

az webapp config set \

  --resource-group MyResourceGroup \

  --name mywebapp \

  --always-on true


Application Gateway or Front Door

Use Azure Front Door for global routing, SSL termination, and caching.


Caching

  • Use in-app caching (Redis, MemoryCache, etc.)
  • Integrate with Azure Cache for Redis for enterprise scenarios

🧪 6. Monitoring and Diagnostics

🔧 Enable Diagnostic Logs

bash

 

az webapp log config \

  --name mywebapp \

  --resource-group MyResourceGroup \

  --application-logging true \

  --level information

📂 Log Options

Type

Purpose

Application Logs

Logs from app code (stdout/stderr)

Web Server Logs

HTTP requests/responses

Detailed Error Messages

4xx and 5xx error traces

Failed Request Tracing

Request-level diagnostic data


📈 View Performance with Application Insights

Application Insights provides:

  • Request counts
  • Response times
  • Exception tracking
  • Live metrics dashboard

Linking:

bash

 

az webapp config appsettings set \

  --name mywebapp \

  --resource-group MyResourceGroup \

  --settings APPINSIGHTS_INSTRUMENTATIONKEY=<your-key>


📋 Summary Table – Configuration & Scaling Overview


Feature

Tool/Setting

Environment Variables

App Settings or az webapp config appsettings

Secure Secret Storage

Azure Key Vault

Runtime Stack & Version

App Configuration or CLI

Scaling (Manual & Auto)

Azure Portal / az webapp scale

Always On

Configuration Settings

Monitoring & Logs

Application Insights / Diagnostic Logs

Back

FAQs


❓1. What is Azure App Service?

Answer:
Azure App Service is a fully managed Platform as a Service (PaaS) from Microsoft that allows you to host web applications, RESTful APIs, and mobile backends. It supports various languages like .NET, Node.js, Python, Java, and PHP.

❓2. What types of applications can I deploy on Azure App Service?

Answer:
You can deploy web apps (e.g., React, Angular, .NET MVC), APIs (Node.js, Flask, Express), static sites, background jobs, and containerized applications. Azure App Service supports both Linux and Windows environments.

❓3. Does Azure App Service support custom domains and SSL?

Answer:
Yes. You can map a custom domain to your web app and enable HTTPS using either App Service-managed SSL certificates or your own custom certificates.

❓4. How do I deploy my application to Azure App Service?

Answer:
You can deploy using:

  • Visual Studio or VS Code
  • Azure CLI (az webapp deploy)
  • GitHub Actions or Azure DevOps
  • FTP/Zip deploy
  • Docker and Azure Container Registry

❓5. Can Azure App Service scale automatically?

Answer:
Yes. App Services can scale vertically (increase compute resources) or horizontally (add instances). Autoscaling rules can be based on CPU usage, memory, or HTTP queue length.

❓6. What is the difference between App Service Plan and App Service?

Answer:
An App Service Plan defines the region, OS, pricing tier, and resource allocation (CPU/RAM) for one or more web apps. The App Service is the actual web application hosted within that plan.

❓7. How does deployment slot swapping work?

Answer:
Deployment slots (e.g., staging, production) allow you to deploy your app to a staging environment, test it, and then swap it into production without downtime.

❓8. What pricing options are available for App Services?

Answer:
Azure App Services offer:

  • Free Tier: for learning and testing
  • Shared and Basic: for small workloads
  • Standard and Premium: for production apps with scaling, staging, and high availability
    Pricing depends on compute size, number of instances, and features.



❓9. Is Azure App Service secure?

Answer:
Yes. It offers built-in security features such as HTTPS, DDoS protection, Azure Active Directory authentication, integration with Azure Key Vault, and compatibility with Azure Defender.

❓10. Can I use Azure App Service for CI/CD?

Answer:
Absolutely. Azure App Service integrates with GitHub, Bitbucket, and Azure DevOps for automated deployments and pipelines. It also supports custom scripts and Docker builds.