This repository contains an implementation of a two-region web application architecture on Azure. The architecture ensures high availability and disaster recovery by utilizing multiple Azure regions, Azure Front Door, Cosmos DB, Azure Queue Storage, Azure Functions, Azure Cache for Redis, and more.
The main components of this architecture include:
- Azure Front Door: Provides global load balancing and secure, fast, and reliable content delivery with automatic failover.
- Azure App Service: Hosts the web application and APIs that interact with Azure Functions and other backend services.
- Azure Functions: Executes background tasks and handles failover scenarios.
- Azure Cosmos DB: Provides globally distributed, multi-region data storage.
- Azure Cache for Redis: Caches data to reduce load on the Cosmos DB and speed up response times.
- Azure Queue Storage: Queues tasks for background processing by Azure Functions.
- Static Web App: A React-based front-end for managing inventory and monitoring the health of the application.
graph TD
subgraph Client
A[Browser Client] --> B[Static Web App]
end
subgraph Azure
B --> C[Azure Front Door]
C --> D1[Azure App Service - Primary]
C --> D2[Azure App Service - Secondary]
D1 --> E1[Azure Queue Storage - Primary]
D2 --> E2[Azure Queue Storage - Secondary]
E1 --> F1[Azure Function - Background Task - Primary]
E2 --> F2[Azure Function - Background Task - Secondary]
F1 --> G1[Azure Cosmos DB - Primary]
F2 --> G2[Azure Cosmos DB - Secondary]
F1 --> H1[Azure Cache for Redis - Primary]
F2 --> H2[Azure Cache for Redis - Secondary]
C --> I[Azure Function - Failover Monitor]
I --> F1
I --> F2
H1 <-- Replicates --> H2
G1 <-- Multi-Region Replication --> G2
end
classDef primary fill:#6aa84f,stroke:#333,stroke-width:2px;
classDef secondary fill:#e06666,stroke:#333,stroke-width:2px;
class D1,E1,F1,G1,H1 primary;
class D2,E2,F2,G2,H2 secondary;
-
Azure Cosmos DB Replication:
- The line labeled
Multi-Region Replication
betweenG1[Azure Cosmos DB - Primary]
andG2[Azure Cosmos DB - Secondary]
indicates the native multi-region replication enabled by Azure Cosmos DB.
- The line labeled
-
Azure Cache for Redis Replication:
- The line labeled
Replicates
betweenH1[Azure Cache for Redis - Primary]
andH2[Azure Cache for Redis - Secondary]
represents the custom replication mechanism that uses an Azure Function or another service to replicate data from the primary Redis cache to the secondary.
- The line labeled
-
Azure Functions and App Services:
Azure Function - Background Task
processes tasks from the Azure Queue Storage in both regions and interacts with Cosmos DB and Redis Cache.Azure Function - Failover Monitor
checks the health of the primary region and initiates failover if necessary, interacting with both background task functions.
The frontend is a React-based dashboard for managing inventory and monitoring application health. It interacts with the Azure App Service API to perform CRUD operations on inventory items and checks the health status of the application.
- Add Inventory Items: Allows administrators to add new inventory items.
- View Inventory Items: Displays the current inventory items.
- Monitor Health: Provides a health check of the primary and standby regions.
To run the React app locally:
-
Install dependencies:
npm install
-
Run the app:
npm start
-
The app will be available at
http://localhost:3000
.
The Azure App Service hosts a RESTful API that allows you to manage inventory items. The API has the following endpoints:
- POST /api/inventory/add-item: Adds a new inventory item.
- GET /api/inventory/get-item/{id}: Retrieves an inventory item by ID.
- GET /api/health: Returns the health status of the application.
-
Add an Inventory Item
curl -X POST "https://your-api.azurewebsites.net/api/inventory/add-item" -H "Content-Type: application/json" -d '{ "id": "12345", "name": "Sample Item", "quantity": 10, "location": "Warehouse 1" }'
-
Get an Inventory Item
curl -X GET "https://your-api.azurewebsites.net/api/inventory/get-item/12345"
-
Check Health Status
curl -X GET "https://your-api.azurewebsites.net/api/health"
Azure Functions perform background tasks and monitor failover scenarios:
- Background Task Function: Processes tasks from the Azure Queue Storage and updates Cosmos DB.
- Failover Function: Periodically checks the health of the primary region and initiates failover if necessary.
Azure Cosmos DB provides a globally distributed, multi-region data store. All inventory data is stored in Cosmos DB, ensuring low latency and high availability across multiple Azure regions.
To deploy the solution, follow these steps:
- Fork this repository and clone it locally.
- Set up the required GitHub Secrets in your repository settings.
- Push changes to the
main
branch to trigger the deployment workflows.
Ensure you have the following secrets set in your GitHub repository:
AZURE_CREDENTIALS
: Azure service principal credentials in JSON format.AZURE_RESOURCE_GROUP
: The Azure resource group name.AZURE_LOCATION
: The primary region for deployment (e.g.,eastus
).AZURE_LOCATION_SECONDARY
: The secondary region for deployment (e.g.,westus
).AZURE_APP_SERVICE_NAME
: The name of the Azure App Service.AZURE_APP_SERVICE_PUBLISH_PROFILE
: Publish profile of the Azure App Service.AZURE_FUNCTION_APP_NAME_RETRY
: The name of the Azure Function App handling retry logic.AZURE_FUNCTION_APP_NAME_FAILOVER
: The name of the Azure Function App handling failover logic.AZURE_FUNCTION_APP_PUBLISH_PROFILE_RETRY
: Publish profile for the retry Azure Function App.AZURE_FUNCTION_APP_PUBLISH_PROFILE_FAILOVER
: Publish profile for the failover Azure Function App.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please see the contributing guidelines for more details.