Azure Application Gateway resiliency
Application Gateway is a regional, zone-redundant service. It is a single shared resource per environment, so ION’s resiliency work covers four things:
- The gateway must survive an instance or zone failure and scale with load.
- It must detect and remove an unhealthy backend quickly.
- Changes must not break every hostname at once, because the gateway is shared.
- The gateway must be the fallback path when Front Door is down.
Targets come from ADR-0017 (99.9% SLO and the per-scenario recovery objectives). Capacity numbers come from the capacity model.
Failure modes
| Failure | Detected by | Gateway behavior | User impact | Recovery |
|---|---|---|---|---|
| Instance failure | Platform health, CapacityUnits and request metrics | Remaining instances take the load. Autoscale adds instances | None to brief latency | Automatic |
| Availability zone failure | Resource Health, platform | Instances in the other two zones keep serving | Possible brief errors on in-flight connections | Automatic |
| Autoscale ceiling reached | CapacityUnits near maximum, rising latency and 5xx | Requests queue or fail when load exceeds maximum capacity | Slow or failing requests on every hostname | Raise the maximum, shed load |
| Backend pool has no healthy host | Probe, UnhealthyHostCount, 502 responses | The gateway returns 502 Bad Gateway for that listener | One portal or the API is unavailable | Fix the backend (graceful degradation) |
| Probe too slow | Delayed UnhealthyHostCount, user reports | The gateway keeps sending traffic to a dead host until the probe flips | Errors for 90 s or more per failure | Tighten probes (probe design) |
| Bad listener, rule, or rewrite change | Post-deploy regression suite, error alerts | Serves the misconfiguration to every hostname that shares the rule set | Anything from one path to every portal | Revert the PR and redeploy (change safety) |
| Certificate expired or Key Vault unreadable | Certificate expiry alert, Key Vault logs | TLS handshake fails on every listener | Every agw-* hostname fails, and Front Door fails over to priority 2 | Rotate the certificate, restore the identity role |
Gateway failure or 502 on the health path | Front Door origin health on multi-origin groups | Not serving | REST fails over to priority 2. SignalR WebSocket stops | Interaction with Front Door |
| Zonal public IP or DDoS event | DDoS telemetry, public IP metrics | Platform mitigation | Short degradation | Azure DDoS protection |
| Regional (Switzerland North) outage | Resource Health, synthetic checks | Not available | Whole platform down | Regional DR, not the gateway |
Zones and capacity
The gateway runs across zones 1, 2, and 3 with autoscale.
| Setting | Guideline | Current |
|---|---|---|
| Zones | MUST be 1, 2, and 3 in every environment | ["1","2","3"], hardcoded in the module |
| Minimum capacity | MUST be 2 or more in mgtgma and mgtprd | 2, hardcoded in the module |
| Maximum capacity | MUST be sized from the capacity model | 10, hardcoded in the module |
| Capacity alert | MUST alert at 80% of the maximum | None |
| Configurability | Minimum and maximum MUST be Terraform variables | Not variables |
Capacity is not unlimited. A maximum that is too low turns a traffic spike into errors on every hostname, because they share the gateway. Size the maximum from the peak request rate and TLS connection rate in the capacity model, and revisit it when a new frontend is added.
Probe design
Application Gateway probes each backend directly, from each gateway instance. A host that fails the configured number of consecutive probes is removed from the pool until a probe succeeds again.
| Setting | Guideline | Current |
|---|---|---|
| Interval | 10 to 15 s | 30 s on every probe |
| Timeout | 5 to 10 s, always below the interval | 30 s on every probe, equal to the interval |
| Unhealthy threshold | 2 or 3 | 3 on every probe |
| Success codes | The narrowest set the endpoint returns | 200-399 (SignalR probes 200; blob probes also accept 400) |
| Host header | The backend FQDN, matching the HTTP settings | Matches |
Use real health paths
| Backend | Probe path | Notes |
|---|---|---|
| Shared APIM | /status-0123456789abcdef | The APIM gateway status endpoint. It does not call backends |
| Azure SignalR | /api/health | The managed service health endpoint |
| SPA hosts (App Service and Static Web Apps) | / | Returns the SPA shell |
| Blob storage backends | / | The blob service root returns 400 for anonymous requests, so the probe accepts 400 as reachable |
Connection draining
Connection draining lets existing requests finish when a backend host is removed from a pool, for example during App Service scale-in or a deployment. It is not configured today.
- Connection draining SHOULD be enabled on any backend pool with more than one instance, with a timeout that covers the longest normal request (the request timeout is 30 s today).
- Single-instance and managed-service pools (SignalR, Static Web Apps) gain nothing from it.
- The gap is tracked in implementation.
Interaction with Front Door failover
Front Door treats Application Gateway as priority 1 and a direct origin as priority 2. The Front Door health probe for the API group travels through the gateway to APIM. So the gateway is detected as failed when any of these is true:
- the gateway is unreachable or returns
502; - the certificate fails TLS validation;
- APIM is down, because the probe path ends at APIM.
Failover speed depends on the Front Door probe interval, not the gateway probe. The Front Door timing is in the Front Door resiliency page. The priority-2 path skips the gateway and therefore skips its rewrites, so priority-2 origins need their own header and CORS handling.
Change safety
One gateway serves every agw-* hostname in an environment. A bad change to a
shared object affects all of them. Shared objects include the gateway-rewrite-ruleset
CORS set, the gateway-pool, certificates, probes, and routing-rule priorities.
There is one gateway per environment, and ION does not run a second gateway for now. Blast radius is limited by process instead.
The regression suite
rome-ion/infrastructure/hub/hub-test-suite is the post-deployment gate for both
Front Door and Application Gateway. It is asynchronous (asyncio and httpx),
measures latency, checks TLS certificate expiry, and writes an HTML report.
| Aspect | State |
|---|---|
| Entry point | main.py --infra agw --env <apa, bta, or gma> |
| Route definitions | agw_routes.yaml (gateway) and afd_routes.yaml (Front Door) |
| Coverage | The default and agw-api listeners (health path, plus a Bondi BFF call), Alya shell API calls (customers, incidents, service requests, SignalR negotiate modification), and the web listeners for the Alya shell, automation workbench, Ioniq, service management, customer, incidents management, security posture improvement, and investigation workbench |
| Not covered | Portal shell, portal core, and lobotomy listeners, the docs-site listener, the SignalR WebSocket hostnames, rewrite parity with Front Door, and CORS headers |
| Production | The route files define apa, bta, and gma. There is no prd run, so production relies on gamma plus a manual smoke test |
Extending the suite to cover every listener is an implementation task. A listener that the suite does not test is a listener whose breakage is found by users.
The gateway as the outage bypass
When Front Door fails, the gateway is the fallback. It is already prepared for this:
- every
agw-*hostname resolves to the gateway; - the Alya shell hostname has path rules that mirror Front Door’s
/api/*rewrites; - the per-app header set adds security headers when
X-Azure-FDIDis absent; - the Alya Entra callback URL and the APIM CORS list include the gateway hostname.
The steps and the approval path are in the Front Door manual bypass runbook. The gateway NSG allows internet traffic on 443 today, so no NSG change is needed. Once Front Door-only enforcement exists (target state, see security), the bypass is a human change that makes the gateway reachable from the internet for the declared incident.
Observability and alerts
Diagnostic settings are applied through Azure Policy. They send access and performance logs to the Switzerland North Log Analytics workspace. These alerts MUST exist in every environment, routed to the CPE action group:
| Alert | Signal | Why |
|---|---|---|
| Resource Health | Gateway health degraded or unavailable | Detects a platform incident. In production only today |
| Unhealthy host count | UnhealthyHostCount above zero, per backend pool | A backend was removed from a pool |
Backend 5xx | BackendResponseStatus with status group 5xx above baseline | Backend failures and bad deployments |
| Failed requests | FailedRequests above baseline | The gateway itself failed to serve |
| Capacity units | CapacityUnits above 80% of the maximum | Autoscale is close to its ceiling |
| Backend connect time | BackendConnectTime above baseline | A backend is slow to accept connections before it fails |
| Certificate expiry | Key Vault certificate near-expiry, 30 days or less | An expired certificate fails every listener |
Today only the production Resource Health alert exists. There are no metric alerts.
scripts/get_cert_renewal_status.py checks App Service Certificate orders and posts
to Teams, but nothing schedules it. It is not an expiry alert.
Drills
- Stop one gateway instance, or force a zone failover in a non-production environment, and confirm no user-visible errors.
- Disable a backend and measure the time until
UnhealthyHostCountrises and the listener returns502. Compare it with the probe settings. - Run the Front Door bypass end to end at least once a year in a non-production environment, including sign-in, MFE load, API calls, and SignalR.
- Deploy a harmless change through all four environments with the regression suite and confirm each gate runs.