Regions, zones and high availability

Junior Frequently asked 5 min

On this page

The question

What is the difference between a region and an availability zone?

30-second answer

A region is a geographic area, such as Frankfurt or Ireland, with its own independent copy of the provider's services. An availability zone is one or more data centers inside a region, with separate power, cooling and network, a few kilometers from the others and linked by fast, low-latency connections. Spreading a service over two or three zones survives a data center failure with synchronous replication; surviving the loss of a whole region needs a second region.

Understand it

Take a zone down: what survives

Explore

A normal day. App instances run in three zones behind a load balancer; the database keeps a synchronous standby in zone B.

View as text

Region 1 drawn as three zones, A, B and C, each a column holding app instances and the database copies the chosen deployment places there; below it, region 2, used only by the two-region deployment. Under the drawing, the downtime and the data lost for the chosen failure.

Normal day: A normal day. App instances run in three zones behind a load balancer; the database keeps a synchronous standby in zone B.

One zone, zone fails: Zone A fails and takes the only app and database with it. You rebuild elsewhere from the last backup: hours down, and every write since that backup lost.

Three zones, zone fails: Zone A fails. The load balancer drops it and the database promotes its synchronous standby in zone B: about a minute of errors, no data lost. That is high availability.

Three zones, region fails: The whole region fails. Three zones do not help when all are inside it: you restore elsewhere from copied backups. Zones give high availability, not disaster recovery.

Two regions, region fails: The whole region fails. You promote the replica in region 2, scale its app and move DNS: minutes down, losing the few seconds of writes not yet replicated.

Region 1 drawn as three zones, A, B and C, each a column holding app instances and the database copies the chosen deployment places there; below it, region 2, used only by the two-region deployment. Under the drawing, the downtime and the data lost for the chosen failure.

Normal day: A normal day. App instances run in three zones behind a load balancer; the database keeps a synchronous standby in zone B.

One zone, zone fails: Zone A fails and takes the only app and database with it. You rebuild elsewhere from the last backup: hours down, and every write since that backup lost.

Three zones, zone fails: Zone A fails. The load balancer drops it and the database promotes its synchronous standby in zone B: about a minute of errors, no data lost. That is high availability.

Three zones, region fails: The whole region fails. Three zones do not help when all are inside it: you restore elsewhere from copied backups. Zones give high availability, not disaster recovery.

Two regions, region fails: The whole region fails. You promote the replica in region 2, scale its app and move DNS: minutes down, losing the few seconds of writes not yet replicated.

Takeaway: Spreading over availability zones survives a data center failure in about a minute with no data lost: high availability. Only a second region survives losing the whole region: disaster recovery, with some downtime and data loss.

What each failure needs, zones for high availability and regions for disaster recoveryA region is a geographic area with several availability zones, each one or more separate data centers with their own power and network. Losing a host or a zone is handled by high availability, running in two or three zones with synchronous replication, measured in seconds to a minute. Losing a whole region is handled by disaster recovery, a second region with copied backups or asynchronous replicas, measured by the RTO and RPO you agreed.a host or a zonethe whole regionRegion:eu-west-13 availability zones:separate power,networkWhat fails?High availability:spread over zones,sync replicationDisaster recovery:second region,async copiesseconds to a minute,no data lostwithin the agreedRTO,losing at most theRPO
What each failure needs, zones for high availability and regions for disaster recoveryA region is a geographic area with several availability zones, each one or more separate data centers with their own power and network. Losing a host or a zone is handled by high availability, running in two or three zones with synchronous replication, measured in seconds to a minute. Losing a whole region is handled by disaster recovery, a second region with copied backups or asynchronous replicas, measured by the RTO and RPO you agreed.a host or a zonethe whole regionRegion:eu-west-13 availability zones:separate power,networkWhat fails?High availability:spread over zones,sync replicationDisaster recovery:second region,async copiesseconds to a minute,no data lostwithin the agreedRTO,losing at most theRPO
What each failure needs: zones for high availability, regions for disaster recovery
ConceptAWS (Amazon Web Services)AzureGCP (Google Cloud Platform)
Region, zoneRegion, Availability ZoneRegion, availability zoneRegion, zone
Database across zonesRDS (Relational Database Service) Multi-AZZone-redundant SQL DatabaseCloud SQL high availability
Replica in another regionAurora Global Database, cross-region read replicaActive geo-replication, failover groupsCloud SQL cross-region replica
DNS (Domain Name System) failoverRoute 53 failover routingTraffic Manager, Front DoorCloud DNS failover routing

In code

aws ec2 describe-availability-zones --region eu-west-1 --query 'AvailabilityZones[].ZoneName'
# [ "eu-west-1a", "eu-west-1b", "eu-west-1c" ]

# A synchronous standby in a second AZ (availability zone): automatic failover, no data lost
aws rds create-db-instance --db-instance-identifier orders-db --engine postgres \
  --db-instance-class db.m7g.large --allocated-storage 100 \
  --master-username orders --manage-master-user-password \
  --multi-az --backup-retention-period 7
A region lists its zones; a database spread over two zones is one flag
resource "aws_autoscaling_group" "orders" {
  name                = "orders"
  min_size            = 3
  max_size            = 9
  vpc_zone_identifier = [for s in aws_subnet.private : s.id] # one subnet per zone
  target_group_arns   = [aws_lb_target_group.orders.arn]
  health_check_type   = "ELB"

  launch_template {
    id      = aws_launch_template.orders.id
    version = "$Latest"
  }
}

resource "aws_db_instance" "orders" {
  identifier                  = "orders-db"
  engine                      = "postgres"
  instance_class              = "db.m7g.large"
  allocated_storage           = 100
  username                    = "orders"
  manage_master_user_password = true
  multi_az                    = true
  backup_retention_period     = 7
}
Terraform: app instances in three zones, the database standby in another
# Wrong: this IP belongs to the primary in zone A and dies with it
 Wrong spring.datasource.url=jdbc:postgresql://10.0.1.23:5432/orders
# Right: a DNS name the provider moves to the new primary, with short timeouts so pools reconnect fast
 Right spring.datasource.url=jdbc:postgresql://orders-db.abc123.eu-west-1.rds.amazonaws.com:5432/orders
 Right spring.datasource.hikari.connection-timeout=5000
 Right spring.datasource.hikari.max-lifetime=600000
Point the app at the failover endpoint, never at one instance's address
public class OrdersApplication {
    public static void main(String[] args) {
        // Without a security manager the default is 30 s; set it before the first lookup
        java.security.Security.setProperty("networkaddress.cache.ttl", "5");
        java.security.Security.setProperty("networkaddress.cache.negative.ttl", "1");
        SpringApplication.run(OrdersApplication.class, args);
    }
}
The JVM (Java Virtual Machine) caches DNS answers; keep the cache short so a moved endpoint is followed
A Multi-AZ database failover, as the app sees itThe primary in zone A stops responding. The provider promotes the synchronous standby in zone B and points the database DNS name at it. The app's open connections fail, the pool opens new ones, resolves the name again and reaches the new primary. Writes were synchronous, so nothing committed is lost.Standby, zone BPrimary, zone ADB endpoint (DNS)orders appzone A failsabout a minute of errors, no committed data lostINSERT order (sync copy to B)promoted to primaryendpoint now points to Bpool reconnects, resolves againINSERT order
A Multi-AZ database failover, as the app sees itThe primary in zone A stops responding. The provider promotes the synchronous standby in zone B and points the database DNS name at it. The app's open connections fail, the pool opens new ones, resolves the name again and reaches the new primary. Writes were synchronous, so nothing committed is lost.Standby, zone BPrimary, zone ADB endpoint (DNS)orders appzone A failsabout a minute of errors, no committed data lostINSERT order (sync copy to B)promoted to primaryendpoint now points to Bpool reconnects, resolves againINSERT order
A Multi-AZ database failover, as the app sees it

Solve it

Choose a recovery design for RTO 1 hour and RPO 5 minutes

A payments service runs in one region across three zones, with a Multi-AZ PostgreSQL database and nightly snapshots copied to a second region. The business now asks that losing the whole region costs at most one hour of downtime, the RTO (recovery time objective), and at most five minutes of payments, the RPO (recovery point objective). Choose a design, and justify its cost.

  1. Translate the numbers. RPO 5 minutes means data must leave the region continuously; a nightly snapshot loses up to 24 hours. RTO 1 hour means the second region needs ready infrastructure, not a rebuild from nothing.
  2. Rule out what fails. Backup and restore misses both targets. Active-active in two regions meets them but brings multi-region writes and conflicts, which is far more than an hour of downtime is worth.
  3. Pick warm standby or pilot light. Keep an asynchronous cross-region read replica, whose lag is seconds, plus the app’s infrastructure as code. Pilot light keeps it scaled to zero; warm standby keeps one small instance running.
  4. Write the failover runbook. Promote the replica, scale the app, switch DNS (Domain Name System) with a short TTL (time to live), then check payments that were in flight. Make it one script, not a page of manual steps.
  5. Check by testing. Run a game day: fail the region on purpose, time it against one hour, and compare the last replicated payment with the last one written. Alert when replica lag nears five minutes.
provider "aws" {
  alias  = "dr"
  region = "eu-central-1"
}

resource "aws_db_instance" "payments_dr" {
  provider                = aws.dr
  identifier              = "payments-db-dr"
  replicate_source_db     = aws_db_instance.payments.arn
  instance_class          = "db.m7g.large"
  storage_encrypted       = true
  kms_key_id              = aws_kms_key.dr.arn # KMS (key management service) keys are regional
  backup_retention_period = 7
}

# Failover, from the runbook:
#   aws rds promote-read-replica --db-instance-identifier payments-db-dr --region eu-central-1
A cross-region read replica: seconds of lag, promoted when region 1 is lost

How to answer

  • Zones in a region are close enough for synchronous replication, around a millisecond apart.
  • Regions are far apart and independent, so copies between them are asynchronous.
  • Pick a region for latency to users, data residency law, price and the services it offers.
  • Most managed services are zonal or regional; know which, because it decides what a failure takes down.

Common mistakes

  • Treating three zones in one region as protection against a regional outage.
  • Believing one availability zone is one building that can only fail as a whole.

Follow-up questions

What is the difference between high availability and disaster recovery?

HA (high availability) keeps a service running through common failures, such as a crashed instance, a failed disk or a lost zone, automatically and within seconds to a minute, with redundancy across zones. DR (disaster recovery) restores service after a rare, large loss, such as a whole region, a corrupted database or a deleted account, within agreed targets, from backups or replicas in another region. HA is measured in uptime; DR in RTO and RPO.

  • HA is automatic and continuous; DR is a plan you trigger and rehearse.
  • Replication is not a backup; a bad delete replicates instantly, so DR needs point-in-time backups too.
  • A DR plan that was never tested is a hope, not a plan.

See it in the infographic: Take a zone down: what survives

What are RTO and RPO, and how do they drive the design?

The RTO (recovery time objective) is the longest downtime the business accepts after a disaster; the RPO (recovery point objective) is the most data, measured in time, it accepts to lose. RPO decides how data is copied: nightly backups give up to 24 hours, continuous asynchronous replication seconds, synchronous replication zero. RTO decides how ready the second site is: rebuilt from scratch, prepared, or already serving.

  • Lower targets cost more, so set them per service with the business, not one for everything.
  • RPO is about data copies; RTO about ready infrastructure and a rehearsed runbook.
  • Measure both in a game day; the real numbers are usually worse than the plan.

See it in the infographic: Take a zone down: what survives

What disaster recovery strategies exist, from cheapest to most resilient?

Four, in order of cost. Backup and restore: copy backups to another region and rebuild there, hours of RTO. Pilot light: replicate the data continuously and keep the infrastructure as code ready but scaled to zero, tens of minutes. Warm standby: a small, running copy of the whole stack, scaled up on failover, minutes. Multi-site active-active: every region serves traffic all the time, near-zero RTO and RPO, but with multi-region writes and the highest cost.

  • Match the strategy to each service's RTO and RPO, not to the most critical one.
  • Infrastructure as code makes the cheaper strategies fast, because rebuilding is a script.
  • Active-active needs data designed for it, such as conflict-free writes or a global database.

See it in the infographic: Take a zone down: what survives

Why not replicate a database synchronously between two regions?

Because every commit would wait for a round trip of tens of milliseconds, slowing every write, and a network problem between regions would block writes in both. So cross-region copies are asynchronous and lose the last seconds on failover. Systems that need global strong consistency, such as Spanner, pay with consensus across regions and higher write latency.

Check yourself

1. A service runs in three availability zones of one region. The whole region becomes unavailable for six hours. What happens?
Show answers
  • It is down until the region returns, unless it can be restored in another region: Correct. All three zones are inside the failed region; zones give HA, not DR.
  • It fails over to the other two zones automatically: Incorrect. The other zones are part of the same region and fail with it.
  • Nothing happens; three zones mean no single point of failure: Incorrect. The region itself is the single point of failure here.
2. The only copy outside the region is a database snapshot taken every night at 02:00. A regional disaster strikes at 18:00. What is the RPO you actually achieve?
Show answers
  • About 16 hours of data lost: Correct. Everything written since the 02:00 snapshot is gone.
  • Zero, because snapshots are complete: Incorrect. A snapshot is complete only up to the moment it was taken.
  • The time it takes to restore the snapshot: Incorrect. That is the RTO, the downtime, not the data lost.