Regions and zones
Why QuickCart runs in two buildings at once.
Part 1: The problem
QuickCart now runs on AWS. Leo set up two servers behind a load balancer, so that if one crashed, the other would keep taking orders. It felt safe.
One Friday evening, every order failed at once. Both servers had stopped answering. Neither had crashed. The building they were in had lost power.
Leo had picked the same place for both servers, because it was the default choice on the form. Two servers in one building is still one building.
So QuickCart needs to know two things: where AWS’s computers physically are, and how to spread across them so that one building failing is a non-event.
Part 2: The idea
AWS isn’t one giant computer in one place. It’s many buildings, in many parts of the world, grouped in two levels: regions and availability zones.
A region is a part of the world
A region is a separate area where AWS runs a complete copy of its services, such as Northern Virginia, Ireland or Tokyo. Each has a code:
| Region code | Where it is |
|---|---|
us-east-1 | Northern Virginia, USA |
eu-west-1 | Ireland |
eu-central-1 | Frankfurt, Germany |
ap-south-1 | Mumbai, India |
ap-southeast-2 | Sydney, Australia |
There are more than 30 regions, and AWS adds more every year. Regions are kept deliberately separate from each other, so a problem in one rarely spreads to another. Most things you create belong to one region and are invisible from the others.
You choose a region for four reasons:
| Reason | What it means for QuickCart |
|---|---|
| Distance to customers | A server in Virginia answers a customer in New York faster than one in Sydney |
| The law | Some countries require certain data, such as customers’ personal details, to stay inside them |
| Price | The same server costs different amounts in different regions |
| Which services exist there | New AWS services often arrive in us-east-1 first |
This course uses us-east-1 everywhere. It’s one of the cheapest regions, and it has every service.
An availability zone is a building, or a few
Inside each region are several availability zones, usually called zones or AZs. A zone is one or more data centres with their own power, cooling and network. AWS keeps zones in the same region miles apart, so a fire, flood or power cut hits only one. They’re also close enough (within about 100 km of each other) to be joined by fast private links. A server in one zone can talk to a server in another in a millisecond or two.
us-east-1 has six zones, named us-east-1a to us-east-1f.
What lives where
Every AWS resource is one of three kinds. You need to know which kind a resource is before you can spread it safely:
| Scope | What it means | Examples |
|---|---|---|
| Global | The same everywhere; no region at all | IAM users and roles, Route 53 domain names |
| Regional | Belongs to one region; AWS spreads it across zones for you | VPC, S3 bucket, load balancer (across the zones you pick) |
| Zonal | Lives in exactly one zone; you spread it yourself | Subnet, EC2 server, a server’s disk (EBS volume), NAT gateway |
The zonal ones are where people get caught. A server is zonal, so two servers in one zone share its fate. Spreading them is your job.
Spreading QuickCart across two zones
For QuickCart, “two zones” means a matching set of everything zonal in each:
| Piece | Zone a | Zone b |
|---|---|---|
| Subnets | quickcart-public-a, quickcart-app-a | quickcart-public-b, quickcart-app-b |
| API servers | one or more | one or more |
| Database | the main copy | a standby copy, ready to take over |
| Load balancer | one load balancer, working in both zones at once |
When zone a fails, the load balancer notices that the servers there stopped answering its health checks and sends everything to zone b. The load balancers lesson shows how. The database switches to its standby, which the RDS lesson covers.
Two things make this work, and both cost something:
| Requirement | Why | The cost |
|---|---|---|
| Each zone can carry all the traffic alone | Otherwise the surviving zone is overwhelmed and falls over too | Spare servers, or auto scaling that adds them quickly |
| Data is copied between zones | So the standby database has every order | AWS charges for data moving between zones, about $0.01 per GB each way in us-east-1 (prices change) |
Zone names and zone IDs
Here’s a detail that confuses people. In us-east-1 and other older regions, AWS shuffles the zone names for each account. Your us-east-1a might be a different building from someone else’s us-east-1a. AWS did this so that everybody picking “a” didn’t pile into the same building.
Each zone also has a zone ID, like use1-az2, that means the same building for everyone:
| Example | Same building in every account? | Use it for | |
|---|---|---|---|
| Zone name | us-east-1a | Not necessarily | Everyday work in your own account |
| Zone ID | use1-az2 | Yes | Lining up zones across accounts, such as when two teams share a network |
You’ll mostly use names. Reach for IDs whenever two AWS accounts need to agree on a zone.
Zones versus regions
Two zones protects you against one building failing. That’s by far the most common kind of trouble. It doesn’t protect against a problem across a whole region, like the 2017 S3 outage. For that you’d run a second copy of QuickCart in another region. That’s much more work, so most teams do it only when the business needs it. Environments and regions shows how Terraform makes it practical.
Part 3: See it
Below, on the left, are some of AWS’s regions, with us-east-1 circled. On the right is what’s inside us-east-1: three of its zones, QuickCart’s two servers, and the load balancer in front. Send some orders. Then fail us-east-1a and send them again. Then switch to Two zones and repeat. Try failing the other zones too, and two zones at once.
Some of AWS's regions. Each region is a separate part of the world with its own zones.Drag to turn the globe. Zone spacing is exaggerated so you can see it.
What to notice: in both setups QuickCart had two servers. The only difference was where they ran. Failing a zone that has nothing of yours in it changes nothing. Failing the zone that has everything takes QuickCart down.
Part 4: Do it
Free — you only look around. Nothing in this lab creates anything.
You’ll find the region selector, list the zones in us-east-1 with their zone IDs, and see which things are global, regional and zonal. About 10 minutes. You need to be signed in to the AWS console.
Find the region selector
Look at the top-right corner of the console, next to your account name. The region selector shows the name of the region you’re working in, such as N. Virginia.
Open it.
You should seeA list of regions, each with its name and code, such as US East (N. Virginia) us-east-1 and Europe (Ireland) eu-west-1. Some near the bottom may be marked as not enabled. Newer regions are switched off until you opt in.
Choose US East (N. Virginia) us-east-1. Everything in this course happens there.
List the zones and their IDs
In the AWS console: EC2Dashboard
Find the Zones table. It’s in the dashboard’s service health section.
You should seeSix rows, us-east-1a to us-east-1f, each with a Zone ID from
use1-az1touse1-az6. Which name goes with which ID is specific to your account. Write down which ID yourus-east-1ahas. A colleague’s may be different.If the console layout has moved, look for any table with Zone name and Zone ID columns. In the EC2 console, Settings > Zones shows the same list.
See one subnet per zone
Every account comes with a default VPC in each region, and it has one subnet in each zone. That makes it an easy way to see zones in action.
In the AWS console: VPCSubnets
You should seeSix subnets belonging to the default VPC, one per zone. The Availability Zone column shows
us-east-1atous-east-1f.If there’s no Availability Zone ID column, choose the gear icon above the table, switch Availability Zone ID on, and choose Confirm. Each subnet now shows its zone ID as well. It matches the table from the last step.
See that regions are separate
Open the region selector and choose Europe (Ireland) eu-west-1. Stay on VPC > Subnets.
You should seeA different set of default subnets, in zones named
eu-west-1a,eu-west-1bandeu-west-1c, with IDs startingeuw1-. Nothing fromus-east-1appears here.Switch the region back to US East (N. Virginia) us-east-1.
See what's global
In the AWS console: IAMDashboard
Look at the region selector.
You should seeIt says Global and you can’t change it. Users and roles aren’t in any region. A role works the same in
us-east-1,eu-west-1and everywhere else.Find where AWS reports problems
Type
Healthinto the search bar at the top of the console and open AWS Health Dashboard. Choose Service health. The wording of this menu changes from time to time.You should seeA list of open and recent issues by service and region. When something odd is happening in one zone or region, AWS reports it here. Check it early during an incident, before assuming your own code is to blame.
Clean-up step: Clean up
This lab didn’t create anything, so there’s nothing to delete.
Check that the region selector shows N. Virginia (us-east-1) again, so the next lesson starts in the right place.
You should seeThe region selector reads N. Virginia.
Part 5: Check yourself
QuickCart's two servers both run in us-east-1a. That zone loses power. What do customers see?
Which of these lives in exactly one availability zone?
You and a colleague in another AWS account both put a server in us-east-1a. Are they in the same building?
QuickCart runs in two zones. One fails. What else must be true for customers to notice nothing?
Does running in two zones protect QuickCart if the whole us-east-1 region has a problem?
Part 6: Cheat sheet
| Term | In one line |
|---|---|
| Region | A separate part of the world with its own copy of AWS, such as us-east-1 |
| Availability zone | One or more buildings in a region, with their own power and network |
| Choosing a region | Distance to customers, the law, price, and which services it has |
| Global | IAM, Route 53: no region |
| Regional | VPC, S3 bucket, load balancer: spread across zones for you |
| Zonal | Subnet, EC2 server, EBS disk, NAT gateway: you spread them yourself |
| Two zones | Protects against one building failing. Each zone must carry the full load alone |
| Two regions | Protects against a whole region failing. Much more work |
| Zone name vs ID | us-east-1a can differ between accounts; use1-az2 never does |
| Resources vanished? | Check the region selector first |