Sub topic 5
Regions and Availability Zones
This chapter assumes you know what a server, an operating system, and an application are. It also assumes you know basic networking terms such as IP address and HTTP. You should have read the earlier chapters on virtualization and resource pooling, because regions and zones are how a provider arranges that pooled hardware around the world.
Why location matters
A cloud service feels like it runs "somewhere in the cloud." In practice it runs in a physical building that holds real machines, and that building is in a real place. Where it sits affects four things you care about:
- Latency. Network signals travel at a finite speed. A user in Singapore talking to a server in Virginia waits much longer for each round trip than a user in the same city as the server.
- Availability. A fire, flood, power cut, or network failure can take a building offline. If everything you run is in one building, everything stops together.
- Legal and compliance rules. Some laws and contracts require that certain data stays inside a country or economic area.
- Cost. Prices for the same service often differ between locations.
Providers handle this with a two-level structure: regions and availability zones.
Regions
A region is a separate geographic area where the provider operates a cluster of data centers. Examples of AWS region names are us-east-1 (N. Virginia), eu-west-1 (Ireland), and ap-southeast-1 (Singapore). Other providers use similar ideas under similar names.
Key properties of a region:
- Regions are isolated from each other. They have their own power, networking, and control services. A serious failure in one region should not spread to another.
- Your resources live in one region unless you copy them. If you launch a virtual machine in
eu-west-1, it does not appear inus-east-1. Data is not replicated to other regions automatically, except for services that explicitly offer it. - Regions are largely independent in naming and identity. For example, a machine image ID that works in one region usually does not exist in another. This is why the IaaS example earlier in the tutorial used a placeholder AMI ID and told you to use an image that exists in your region.
- Not every service or feature is in every region. Newer services usually launch in a few regions first.
Choosing a region usually involves four factors:
- Proximity to users. Closer means lower latency.
- Data residency. Where are you legally allowed to store this data?
- Service availability. Does the region offer every service you need?
- Price. Compare the cost of the services you plan to use.
Availability zones
A region is divided into availability zones (AZs). An availability zone is one or more data centers inside a region, with independent power, cooling, and physical security. Zones in the same region are connected by fast, low-latency private networking, and they are placed far enough apart that a local incident, such as a flood or a power failure, is unlikely to hit more than one.
AWS names zones by adding a letter to the region name: us-east-1a, us-east-1b, and so on. Most regions have three or more zones.
The idea is simple: a region is the unit of geography, and a zone is the unit of failure within it. If you run copies of your application in two zones and one zone goes down, the other keeps serving traffic.
The diagram below shows the structure.
Zone names are not the same for every account
Zone letters are mapped to physical zones differently for each customer account. Your us-east-1a may not be the same building as another customer's us-east-1a. The provider does this to avoid every new customer piling into "zone a." If you need to coordinate zones across accounts, use the provider's zone ID, which is the same for everyone. In AWS, a zone ID looks like use1-az1.
Seeing regions and zones with the CLI
The AWS CLI can list both. These commands assume the CLI is installed and has credentials configured.
# List the regions enabled for your account.
aws ec2 describe-regions --query "Regions[].RegionName" --output text
# List the availability zones in one region, with their stable zone IDs.
aws ec2 describe-availability-zones \
--region us-east-1 \
--query "AvailabilityZones[].[ZoneName,ZoneId,State]" \
--output tableThe second command shows the name (us-east-1a), the zone ID (use1-az1), and the state (available). Each region returns its own list, because every call is scoped to one region.
To place a virtual machine in a particular zone, you choose a subnet that lives in that zone. A subnet belongs to exactly one zone, so the subnet is how you pin a resource to a zone:
# The subnet ID below is a placeholder; use a subnet in the zone you want.
aws ec2 run-instances \
--image-id ami-0123456789abcdef0 \
--instance-type t3.micro \
--subnet-id subnet-0123456789abcdef0 \
--count 1Designing for failure
Zones and regions give you two levels of protection, and they cost different amounts of effort.
| Design | Survives | Does not survive | Typical cost and complexity |
|---|---|---|---|
| One zone | Single machine failures, if you add redundancy | Loss of that zone | Lowest |
| Multiple zones, one region | Loss of one zone | Loss of the whole region | Moderate: extra machines plus a load balancer |
| Multiple regions | Loss of a region | Very little | Highest: data replication, traffic routing, duplicated infrastructure |
Spreading across zones within a region is the common baseline for production systems. The zones are close together, so network latency between them is small and replicating data synchronously between them is practical. Spreading across regions is more expensive and harder, because the distance adds latency, and replicating data over that distance forces trade-offs between consistency and speed.
A multi-zone design needs more than copies of the servers:
- A load balancer that sends traffic only to healthy copies in whichever zones are up.
- Data that is available in more than one zone. If your database runs in a single zone, losing that zone loses the application no matter how many web servers you have elsewhere. Managed databases often offer a multi-zone option that keeps a standby copy in another zone.
- Enough spare capacity. If you run two zones at 70% load each and one fails, the survivor must handle 140%. Plan so that the remaining zones can absorb the load.
How this interacts with the service models
The service model decides how much of this work you do yourself.
- IaaS: You place machines, choose zones, and build the load balancing and replication. Nothing is multi-zone unless you make it so.
- PaaS: Many platforms can spread your application across zones with a setting. For example, Elastic Beanstalk can run its instances across several zones behind a load balancer when you configure it. You still choose the region and often the number of zones.
- SaaS: The provider decides where the software runs and how it survives failures. You may still choose a region for your data, if the vendor offers a choice, which matters for residency rules.
This matches the shared responsibility idea covered later in the tutorial: the higher the model, the more of the resilience design the provider carries.
Common mistakes
- Assuming "the cloud" is automatically redundant. A single virtual machine in a single zone fails when that zone fails. Redundancy is something you design or buy.
- Putting the database in one zone while the web tier spans several.
- Forgetting that data transfer between zones and regions can cost money. Cross-zone traffic within a region is often billed at a small per-gigabyte rate, and cross-region transfer usually costs more.
- Hard-coding zone names such as
us-east-1a. Not every account sees the same zones, and a zone can be unavailable for new resources. Look up the available zones instead. - Choosing a region only for price and ignoring latency to users or residency rules.
Summary
A region is a geographic area with isolated infrastructure. An availability zone is an isolated failure domain inside a region. Pick a region for latency, residency, service availability, and price. Spread across zones for resilience against local failures. Go multi-region only when the cost of a regional outage justifies the added complexity.
Exercise
Your application runs on four web servers, all in us-east-1a, with a database in the same zone. The business wants the application to survive the loss of one availability zone. Name three changes you would make.
Show answer
(1) Move or add web servers in at least one other zone, such as us-east-1b, so that each zone holds enough servers to handle the load alone. (2) Put a load balancer in front that health-checks the servers and routes traffic only to healthy ones in any zone. (3) Make the database available in a second zone, for example with a managed multi-zone deployment that keeps a standby copy. Without the third change, losing us-east-1a would still take the database down.
Exercise
A teammate says, "We use the same availability zone name, us-east-1a, in two AWS accounts, so our resources are in the same data center." What is wrong with this reasoning, and what should they use instead?
Show answer
Zone letters are mapped to physical zones separately for each account, so us-east-1a in one account may be a different physical zone from us-east-1a in another. They should compare zone IDs, such as use1-az1, which refer to the same physical zone for every account.