Laptop to Production

Regions and zones

Why QuickCart runs in two buildings at once.

Time
25 minutes
Level
Beginner

Part 1: The problem

QuickCart, the first outage

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 codeWhere it is
us-east-1Northern Virginia, USA
eu-west-1Ireland
eu-central-1Frankfurt, Germany
ap-south-1Mumbai, India
ap-southeast-2Sydney, 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:

ReasonWhat it means for QuickCart
Distance to customersA server in Virginia answers a customer in New York faster than one in Sydney
The lawSome countries require certain data, such as customers’ personal details, to stay inside them
PriceThe same server costs different amounts in different regions
Which services exist thereNew 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.

Key point: Anything that lives in one zone fails with that zone, so run everything that matters in at least two.

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:

ScopeWhat it meansExamples
GlobalThe same everywhere; no region at allIAM users and roles, Route 53 domain names
RegionalBelongs to one region; AWS spreads it across zones for youVPC, S3 bucket, load balancer (across the zones you pick)
ZonalLives in exactly one zone; you spread it yourselfSubnet, 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:

PieceZone aZone b
Subnetsquickcart-public-a, quickcart-app-aquickcart-public-b, quickcart-app-b
API serversone or moreone or more
Databasethe main copya standby copy, ready to take over
Load balancerone 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:

RequirementWhyThe cost
Each zone can carry all the traffic aloneOtherwise the surviving zone is overwhelmed and falls over tooSpare servers, or auto scaling that adds them quickly
Data is copied between zonesSo the standby database has every orderAWS 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:

ExampleSame building in every account?Use it for
Zone nameus-east-1aNot necessarilyEveryday work in your own account
Zone IDuse1-az2YesLining 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.

QuickCart runs in
Fail a zone
A flat world map with some of AWS's regions marked: us-east-1 (N. Virginia), us-west-2 (Oregon), ca-central-1 (Canada (Central)), sa-east-1 (São Paulo), eu-west-1 (Ireland), eu-west-2 (London), eu-central-1 (Frankfurt), eu-north-1 (Stockholm), me-central-1 (UAE), af-south-1 (Cape Town), ap-south-1 (Mumbai), ap-southeast-1 (Singapore), ap-northeast-1 (Tokyo), ap-southeast-2 (Sydney). us-east-1 is circled, with its three zones shown beside it.us-east-1 zonesabc

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.

Inside us-east-1: customers send orders to a load balancer, which sends each one to a server. Three availability zones, us-east-1a, us-east-1b and us-east-1c, sit side by side.Orders: 0 placed, 0 failedCustomersplacing ordersLoad balancersends each order to a healthy serverus-east-1 (N. Virginia)us-east-1aUpNothing running hereus-east-1bUpNothing running hereus-east-1cUpNothing running hereServer 1runningServer 2running
ReadyQuickCart's two servers both run in us-east-1a. Choose Send 6 orders, then fail that zone and send them again.

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.

  1. 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 see

    A 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.

  2. 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 see

    Six rows, us-east-1a to us-east-1f, each with a Zone ID from use1-az1 to use1-az6. Which name goes with which ID is specific to your account. Write down which ID your us-east-1a has. 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.

  3. 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 see

    Six subnets belonging to the default VPC, one per zone. The Availability Zone column shows us-east-1a to us-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.

  4. See that regions are separate

    Open the region selector and choose Europe (Ireland) eu-west-1. Stay on VPC > Subnets.

    You should see

    A different set of default subnets, in zones named eu-west-1a, eu-west-1b and eu-west-1c, with IDs starting euw1-. Nothing from us-east-1 appears here.

    Switch the region back to US East (N. Virginia) us-east-1.

  5. See what's global

    In the AWS console: IAMDashboard

    Look at the region selector.

    You should see

    It 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-1 and everywhere else.

  6. Find where AWS reports problems

    Type Health into 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 see

    A 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.

  7. 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 see

    The 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

On one card
TermIn one line
RegionA separate part of the world with its own copy of AWS, such as us-east-1
Availability zoneOne or more buildings in a region, with their own power and network
Choosing a regionDistance to customers, the law, price, and which services it has
GlobalIAM, Route 53: no region
RegionalVPC, S3 bucket, load balancer: spread across zones for you
ZonalSubnet, EC2 server, EBS disk, NAT gateway: you spread them yourself
Two zonesProtects against one building failing. Each zone must carry the full load alone
Two regionsProtects against a whole region failing. Much more work
Zone name vs IDus-east-1a can differ between accounts; use1-az2 never does
Resources vanished?Check the region selector first

Finished the build and the quiz? Mark it done to fill in its stop on the route map.