05. Reliability / Lesson 1 of 4
Redundancy & Failover
Keep spare copies, and switch to them fast when a part dies.
- 10 min
- Intermediate
- 10 steps
- Uptime99% (warning)
- Downtime / year87.6 hours (warning)
- Request
- Failed request
- Health check
- Write
Step 1 of 10: Every machine fails sooner or later
Read every step as text
Step 1: Every machine fails sooner or later
Disks wear out, power supplies burn, a bad update crashes a process. For this lesson, say one server is up 99% of the time. That sounds high, but it means about 87.6 hours of downtime a year.
With one copy of everything, each of those hours is an outage for every user. The goal is not a machine that never fails. It is a system that keeps working when a machine does.
Do not ask "will it fail?" Ask "what happens to users when it does?"
Step 2: A single point of failure: one copy with no spare
A real request passes a load balancer, an app server and a database. If each is one copy at 99%, all three must be up at once:
0.99 × 0.99 × 0.99 = 97.03%.That is 10.8 days of downtime a year, worse than any single part. Every part with no spare is a single point of failure (SPOF), and a longer chain means lower uptime.
Look for SPOFs by asking of each box: if this one dies right now, does the whole system stop?
Step 3: Active-passive: a standby waits for its turn
Add a second database that only receives a copy of every write. It does no other work. This is active-passive (or primary and standby).
When the primary dies, the standby is promoted and takes over. The pair is down only if both are down at once:
1 − 0.01 × 0.01 = 99.99%. With the database doubled, the whole chain rises to 98%.Active-passive is simple and safe for data that must have one writer, such as a database.
Step 4: Active-active: every copy serves traffic
Run two app servers and two load balancers, and let all of them work all the time. This is active-active. Nothing sits idle, and when one copy dies the other simply takes the whole load.
Every layer is now a pair, so the chain is
99.99%³ = 99.97%, about 2.6 hours a year. Each survivor must be able to carry the full load alone, so plan spare room.Two servers at 70% load each cannot survive a failure: the one left would need 140%. Keep each below 50%, or add a third.
Step 5: Health checks: how the system notices a death
A copy is useless if traffic still goes to the dead one. The load balancer calls
GET /healthon each server every 2 seconds and expects200 OK.After 3 misses in a row it stops sending requests there; when the checks pass again it adds the server back. Three misses, not one, so a single slow reply does not remove a healthy server.
A good health check tests what matters (can it reach its database?), not only that the process is running.
Step 6: Failover is not instant
Three checks 2 seconds apart take 6 seconds to notice a death. Promoting a standby database and reconnecting the app takes more. Say a failover loses 30 seconds in all.
If that happens 4 times a year, it adds
30 × 4 = 120 s(2 minutes). Small here, but it is the part the1 − 0.01²formula forgot.Faster checks find failures sooner but remove healthy servers by mistake. Tune the speed against false alarms.
Step 7: Zones: copies in different buildings
So far, both copies could sit in one building. A power cut or a network fault there kills the pair together. A cloud zone is a separate building with its own power and network. Say a zone is up 99.9% of the time; then one zone caps the whole system at
99.9% × 99.97% = 99.87%.Put one full set in each of two zones. Now the system is down only when both zones are, about
53 splus failovers.Spreading over zones is cheap with cloud providers and is the usual first step for high uptime.
Step 8: Regions: copies in different parts of the world
A region is a group of zones in one area. A bad update, a cloud-wide fault or a flood can take down a whole region. Say a region is up 99.99% of the time. Two regions, each with its own zones, behind a global DNS answer give about 100% on paper, with the same 2 minutes of failover.
The price is real: double the bill, a copy of the data in each region, and a round trip of about 70 ms between them (say). Writes to both regions must wait for that or accept a delay in the copy.
Most systems stop at two zones. Add regions only when an outage would cost more than running a second region.
Step 9: Counting the nines
Uptime is quoted in nines: 99.9% is three nines. Each extra nine cuts the allowed downtime by 10 times: about 8.76 hours a year at 99.9%, 52.6 minutes at 99.99%, and 5.3 minutes at 99.999%.
The paper figures above are a ceiling. Copies fail together more often than the maths assumes: one bad deploy or one wrong setting reaches every copy at once.
Choose the target from the business need. Each extra nine costs far more than the one before.
Step 10: Redundancy in one picture
Remove every single point of failure: two of each part, health checks to find the dead one, and copies in separate zones (and, if worth it, regions). One chain at 97.03% became 100% on paper.
Failover costs seconds, and copies can fail together, so test failovers on purpose before a real failure does it for you.