This project implements a highly available, multi-region Flask application with automatic failover and global load balancing using Azure services. The infrastructure is organized into global and regional modules for better maintainability and deployment efficiency.
Note
Recommended regions: Poland Central and Canada Central (due to ongoing capacity constraints in other regions)
- Azure Developer CLI (azd)
- Azure CLI (optional)
- Azure subscription with appropriate permissions
# Clone and navigate to the project
cd azd-dev-prod
# Deploy using azd (AZURE_ENV_TYPE=dev by default)
azd up
# Or deploy specific environment
azd env set AZURE_ENV_TYPE prod
azd up# Clone and navigate to the project
cd azd-dev-prod
# Configure CI/CD pipeline
azd pipeline configFollow the interactive prompts:
- Environment name: Enter a unique environment name
- Provider: Select
GitHub - Azure Subscription: Choose your target subscription
- Primary Location: Select primary region (recommended:
Canada Central) - Secondary Location: Select secondary region (recommended:
Poland Central) - Authentication: Select
Federated User Managed Identity (MSI + OIDC) - User Managed Identity: Choose to use existing or create new MSI
After running azd pipeline config, you'll need to add environment-specific federated credentials to the User Assigned Managed Identity in Azure:
-
Navigate to your User Assigned Managed Identity resource in the Azure portal
-
Follow the Microsoft documentation to create federated credentials. Do this twice for the
devandprodenvironments: -
Commit and Push: After setting up federated credentials, manually trigger the Deploy workflow or commit your changes to trigger the pipeline
Modular Bicep infrastructure:
infra/
โโโ main.bicep # Main orchestration (subscription scope)
โโโ main.parameters.json # Environment parameters
โโโ abbreviations.json # Azure resource naming abbreviations
โโโ global/ # Global infrastructure components
โ โโโ main.bicep # Global resources (Front Door, DNS, shared storage)
โ โโโ front-door-config.bicep # Front Door endpoint configuration
โโโ regional/ # Regional infrastructure components
โโโ main.bicep # Regional orchestration
โโโ app.bicep # App Service and hosting
โโโ storage.bicep # Regional storage
โโโ network.bicep # VNet and networking
โโโ monitoring.bicep # Regional monitoring
โโโ modules/ # Additional modules
โโโ applicationinsights-dashboard.bicep # Application Insights dashboard
โโโ vnet-link.bicep # VNet links for private DNS zones
- Multi-Resource Group: Resources are deployed to separate resource groups (primary, secondary, global)
- Global Components: Front Door, DNS zones, and shared storage deployed once to global resource group
- Regional Components: App Services, regional storage, and monitoring deployed per region to regional resource groups
- VNet Integration: Private DNS zone links created for production environments
- Service Configuration: Two azd services (
app-primaryandapp-secondary) for automatic deployment
- VNet integration with private endpoints
- Private storage access only
- Private DNS zones with VNet links
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Azure Front Door โ
โ (Global Load Balancer + CDN) โ
โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโโโผโโโโโโโโโโ โโโโโโโโโโโผโโโโโโโโโโ
โ PRIMARY REGION โ โ SECONDARY REGION โ
โ โ โ โ
โ โโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโ โ
โ โ App Service โ โ โ โ App Service โ โ
โ โ (VNet Integ)โ โ โ โ (VNet Integ)โ โ
โ โโโโโโโโฌโโโโโโโ โ โ โโโโโโโโฌโโโโโโโ โ
โ โ โ โ โ โ
โ โโโโโโโโผโโโโโโโ โ โ โโโโโโโโผโโโโโโโ โ
โ โ VNet + Priv โ โ โ โ VNet + Priv โ โ
โ โ Endpoints โ โ โ โ Endpoints โ โ
โ โโโโโโโโฌโโโโโโโ โ โ โโโโโโโโฌโโโโโโโ โ
โ โ โ โ โ โ
โ โโโโโโโโผโโโโโโโ โ โ โโโโโโโโผโโโโโโโ โ
โ โ Storage โ โ โ โ Storage โ โ
โ โ (Private) โ โ โ โ (Private) โ โ
โ โโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโผโโโโโโโโโ
โ Global Storage โ
โ (Shared Config) โ
โโโโโโโโโโโโโโโโโโโ
- Public storage access with managed identity auth
- No VNet or private endpoints
- Simplified networking for faster deployment
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Azure Front Door โ
โ (Global Load Balancer + CDN) โ
โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโโโผโโโโโโโโโโ โโโโโโโโโโโผโโโโโโโโโโ
โ PRIMARY REGION โ โ SECONDARY REGION โ
โ โ โ โ
โ โโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโ โ
โ โ App Service โ โ โ โ App Service โ โ
โ โ (Simplified)โ โ โ โ (Simplified)โ โ
โ โโโโโโโโฌโโโโโโโ โ โ โโโโโโโโฌโโโโโโโ โ
โ โ โ โ โ โ
โ โโโโโโโโผโโโโโโโ โ โ โโโโโโโโผโโโโโโโ โ
โ โ Storage โ โ โ โ Storage โ โ
โ โ (Public + โ โ โ โ (Public + โ โ
โ โ MI Auth) โ โ โ โ MI Auth) โ โ
โ โโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ
| Variable | Description | Default | Example |
|---|---|---|---|
AZURE_ENV_NAME |
Environment name for resource naming | - | my-scale-unit |
AZURE_ENV_TYPE |
Environment type (dev/test/prod) | dev |
prod |
AZURE_LOCATION |
Primary region | eastus |
eastus2 |
AZURE_SECONDARY_LOCATION |
Secondary region | westus2 |
southcentralus |
| Environment | Networking | Security | Use Case |
|---|---|---|---|
dev |
Public access with MI auth | Basic | Development, testing |
prod |
VNet integration + private endpoints | High | Production workloads |
/health- Health check endpoint for Front Door health probes/info- Application information and diagnostics
The application includes a Health Status Control section on the main page for testing load balancer and Front Door failover:
- Open Front Door endpoint
- Click "Make Unhealthy (120s)" button
- Refresh page - traffic should route to the other region
Note
Alternatively, you can use az webapp stop --name <app-service-name> --resource-group <resource-group> to stop one of the apps.
Main Orchestration (main.bicep):
- Subscription-scoped deployment creating separate resource groups
- Orchestrates global and regional deployments in parallel
- Manages VNet links for private DNS zones in production
- Parameter management and output aggregation
Global Infrastructure (global/):
main.bicep: Front Door profile, private DNS zones, global storagefront-door-config.bicep: Endpoint and origin configuration (post-deployment)
Regional Infrastructure (regional/):
main.bicep: Regional orchestration and resource coordinationapp.bicep: App Service Plan and App Service configurationstorage.bicep: Regional storage accounts and containersnetwork.bicep: VNet, subnets, and private endpoints (prod only)monitoring.bicep: Application Insights, Log Analytics, and dashboardsmodules/applicationinsights-dashboard.bicep: Monitoring dashboardmodules/vnet-link.bicep: VNet links to private DNS zones (prod only)
- Resource Groups: Primary, secondary, and global resource groups created
- Global Resources: DNS zones, Front Door profile, shared storage
- Regional Resources: App Services, regional storage, monitoring (parallel deployment)
- VNet Links: Private DNS zone links for production environments
- Front Door Configuration: Endpoints and origins (after App Services are ready)
- Application Deployment: Code deployment to both regions via azd services
๐ฎ Advanced Scenarios
Adding More Regions:
- Modify
main.bicepto add additional regional deployments - Update
azure.yamlto include new service configurations - Configure Front Door origin groups for additional regions
Custom Domains & SSL:
- Configure custom domain in Front Door endpoint
- Upload SSL certificates or use managed certificates
- Update DNS CNAME records to point to Front Door
Database Integration:
- Add Azure SQL Database with geo-replication to
global/main.bicep - Configure connection strings per region in
regional/app.bicep - Implement database failover logic in application code
Security Enhancements:
- Enable WAF (Web Application Firewall) on Front Door
- Configure App Service IP restrictions to Front Door only
- Add Azure Key Vault for secrets management
- Enable Azure AD authentication
Performance Optimization:
- Configure Front Door caching rules
- Enable compression and optimization
- Add Application Gateway for advanced load balancing
- Implement Redis cache for session state

