Expert · High availability, scaling and disaster recovery · topic 39 of 50 · 30 min
Designing for high availability
Explanation
What availability means
Availability is the percentage of time a system does its job for users. If a results website is down for 1 hour in a 100-hour period, its availability is 99%. Engineers talk about "nines": 99.9% is "three nines", 99.99% is "four nines". A service level agreement (SLA) is a promise in a contract, often with a refund (service credit) if it is broken. A service level objective (SLO) is the internal target a team aims for.
| Availability | Downtime per year | Downtime per month (about 30.4 days) |
|---|---|---|
| 99% (two nines) | 3.65 days (87.6 hours) | 7.3 hours |
| 99.5% | 43.8 hours | 3.65 hours |
| 99.9% (three nines) | 8.76 hours | 43.8 minutes |
| 99.95% | 4.38 hours | 21.9 minutes |
| 99.99% (four nines) | 52.6 minutes | 4.38 minutes |
| 99.999% (five nines) | 5.26 minutes | 26.3 seconds |
Every extra nine costs much more money and effort. A college notice board may be fine at 99.5%. A payment switch handling UPI traffic needs far more. Choose the target from what downtime really costs the business, then design for it.
Single points of failure
A single point of failure (SPOF) is any part whose failure takes the whole system down. The classic beginner setup has many: one EC2 instance running both the web app and the database, in one Availability Zone, with files on its own disk. If that instance, its disk or its zone has a problem, everything stops. Other SPOFs hide in plain sight: one NAT gateway, one DNS provider, or one engineer who alone knows the root password.
Multi-AZ design
An Availability Zone (AZ) is one or more data centres in a region with their own power, cooling and network, close enough to other AZs for fast connections. Zones are built to fail independently. So the basic rule of cloud HA is: run at least two of everything in at least two AZs. Put app servers in two or three AZs behind a load balancer, use Amazon RDS Multi-AZ so a standby database in another zone takes over automatically, and use services such as S3 that already store data across several zones.
Stateless app servers
State is data that must be remembered between requests: a login session, a shopping cart, an uploaded file. If a server keeps state on its own memory or disk, users lose it when that server dies, and the load balancer cannot freely send them to another server. A stateless server keeps nothing important locally. Sessions go to a cache such as Amazon ElastiCache or a table in DynamoDB, files go to S3, and records go to the database. Then any server can answer any request, and you can add, remove or replace servers at any time.
Health checks and graceful degradation
A health check is a regular test, such as the load balancer calling GET /health every 15 seconds. A server that fails a few checks in a row is taken out of rotation, and an Auto Scaling group can replace it. Keep the health endpoint honest but simple: if it checks the database and the database blips, every server can be marked unhealthy at once.
Graceful degradation means that when one part fails, the rest keeps working in a reduced way. If the recommendation service is down, the shopping page shows without recommendations. If the database is overloaded, the results site can serve cached pages or switch to read-only mode instead of showing errors to everyone.
Availability maths: series and parallel
Components in series all have to work, like a chain. Their availabilities multiply, so the total is lower than the weakest part. A web tier at 99.9% that needs a database at 99.95% gives 0.999 × 0.9995 = 0.9985, about 99.85%.
Redundant components in parallel only fail if all of them fail at once. With n copies each of availability a, the chance that all are down is (1 − a) to the power n, so the availability is 1 − (1 − a)^n. Two servers at 99% each: 1 − 0.01 × 0.01 = 0.9999, which is 99.99%. Redundancy turns two ordinary servers into four nines, as long as they really fail independently.
lb = 0.9999 # one managed load balancer
app = 1 - (1 - 0.995) ** 2 # two app servers at 99.5% in parallel: 0.999975
db = 0.9995 # Multi-AZ database
total = lb * app * db # the three tiers in series
print(round(total * 100, 3)) # 99.938Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Designing for high availability · 1/7
Availability is the share of time your system works for users. Engineers count it in nines.
Prefer a video by a teacher? Find free videos on “high availability multi az architecture aws availability nines explained” on YouTube ↗
In real life: A university results portal survives a zone failure
A university in Pune moved its results portal from one large server to two small app servers in two Availability Zones of the Mumbai region, behind an Application Load Balancer, with an RDS Multi-AZ database and student sessions in ElastiCache. During the next result day, one zone had a networking problem. The load balancer health checks marked the servers in that zone unhealthy within a minute, traffic moved to the other zone, the Auto Scaling group started replacement servers, and students saw only a short slowdown instead of an outage.
Practice (0/3 done)
Write downtime_hours(pct) that returns how many hours a year a system can be down at a given availability percentage. Use 8,760 hours in a year and round to 2 decimal places. Example: downtime_hours(99.9) returns 8.76.
Write three functions, with availabilities as fractions (0.999 means 99.9%): - series(avails): the availability of components that ALL must work (multiply them). - parallel(a, n): the availability of n redundant copies, each with availability a: 1 - (1 - a) ** n. - three_tier(lb, app, n_app, db): a load balancer, n_app app servers in parallel, and a database, all in series.
An app runs on two EC2 instances in the SAME Availability Zone behind a load balancer. Which failure would still take the whole app down?
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Load balancing and auto scalingHigh availability, scaling and disaster recovery · same module
- Backups and disaster recoveryHigh availability, scaling and disaster recovery · same module
- The Well-Architected FrameworkHigh availability, scaling and disaster recovery · same module
- Scaling: handling more usersBackend Development · Deployment and scaling
- Azure compute and storageMicrosoft Azure essentials
- VPC basics: CIDR, subnets and gatewaysNetworking and databases: VPC and RDS
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
About how much downtime per month does 99.9% availability allow?
Answer: About 43.8 minutes
0.1% of a 730-hour average month is 0.73 hours, about 43.8 minutes.
Why should web servers be stateless in an HA design?
Answer: So any server can handle any request and servers can be replaced without losing user data
With state in shared services, the load balancer can send users anywhere and failed servers can simply be replaced.
A web tier (99.9%) depends on an auth service (99.9%) and a database (99.95%). All three must work. What is the overall availability, roughly?
Answer: 99.75%
In series: 0.999 × 0.999 × 0.9995 ≈ 0.9975, about 99.75%, lower than any single part.
What does a load balancer do when a server fails its health checks several times in a row?
Answer: Stops sending traffic to that server
Unhealthy targets are removed from rotation until they pass checks again.
The recommendation service fails, and the shop still shows products and accepts orders without recommendations. What is this called?
Answer: Graceful degradation
The system keeps its core job working in a reduced form when a non-essential part fails.
Why must servers be stateless to scale horizontally?Related
Answer: Because the next request may go to a different server
If state lives in one server, other servers cannot see it. Shared stores like Redis fix this.
What is an Availability Zone?Related
Answer: One or more data centres in a region with independent power, cooling and networking
AZs are isolated data centres inside one region, joined by low-latency links.
How is data copied to a Multi-AZ standby (DB instance deployment)?Related
Answer: Synchronously, before each write is confirmed
Multi-AZ uses synchronous replication, so the standby has every committed write.
Which redundancy keeps 3 copies across availability zones AND copies in a paired region?Related
Answer: GZRS
GZRS is ZRS in the primary region plus asynchronous copies in the secondary region.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 3 more topics in “High availability, scaling and disaster recovery” before its exam: Load balancing and auto scaling, Backups and disaster recovery, The Well-Architected Framework.
- Module 10 exam: High availability, scaling and disaster recovery · 13 questions · 25 min, without help. 4 topics of this module still to finish first.
- Then the next module, Cloud security and compliance. 50 topics left in the course before the final exam.