AlgoViz

Tech stacks for high availability

medium 30 min

The products that do the jobs of high availability, layer by layer: DNS and CDN, load balancers, application replicas, caches and databases.

Video lesson · Chapter 1 of 6

Build a complete path before copying parts

0:00 / 4:50

Five layers in 85 seconds

1:25Reel coming soon

Theory

Read or listen first. About 2 min.

What it is

A stack is the set of products a request passes through: a name lookup, perhaps a cache near the user, a load balancer, your application, a cache and a database. Each layer needs its own way to survive a failure.

Some layers hold no data, so they are easy: run several and share the traffic. Others hold data, so copies must be kept in step and one of them chosen as the primary. Products differ mostly in how they solve that second problem.

Why it exists

The principles of high availability do not change, but you do not build them from zero. Knowing which tool does which job, and where its promise ends, saves months.

It also prevents a common mistake: buying one very available product and placing it behind a part that is not. Layers multiply, so the whole is worse than the weakest.

A short history

  1. 2001

    HAProxy is released by Willy Tarreau. Software starts to replace expensive balancing hardware.

  2. 2004

    Igor Sysoev releases nginx, a web server that soon also works as a reverse proxy and load balancer.

  3. 2010

    Amazon RDS adds Multi-AZ deployments: a standby database in another zone with automatic failover, as a checkbox.

  4. 2014

    Google opens the source of Kubernetes, which restarts and spreads containers over machines.

  5. 2017

    Cloud Spanner becomes available on Google Cloud, a relational database spread over regions.

Words to know

Layer 4
Balancing by address and port (TCP, UDP), without reading the content.
Layer 7
Balancing by content (HTTP): path, header, cookie.
Zone (AZ)
One or more data centers with their own power and network, inside a region.
Managed service
The provider runs, patches and fails it over.
Replica
A copy that follows a primary.
Consensus store
A small cluster such as etcd that agrees, by majority, on facts like who is the leader.
Pod
The unit Kubernetes runs: one or more containers on one node.

How it works

Step through the idea, or press Play.

Step 1 of 3

List the layers. Every product a request needs, from DNS to disk

Understand it

Start here

The superhero team

Imagine a school play with a superhero team. Every hero has one power, and together they keep the website from falling: the traffic cop (HAProxy or Nginx), the memory keeper (PostgreSQL), the cloud guardian (AWS or Google Cloud) and the team manager (Kubernetes).

Four heroes, and a stand-in
TrafficcopMemorykeeperCloudguardianTeammanagerSecondcopOne hero, every job

Powers are the products. The stand-in is the high availability.

The stack

Five layers of protection

A request through the layers

Users look up the name in DNS, then send requests to a load balancer. The load balancer sends requests to pods on three worker nodes. The pods use a Redis primary with a replica and a PostgreSQL primary with a standby.
Every pod uses both the cache and the database. Stateless layers (balancer, pods) have several equal copies. Stateful layers (Redis, PostgreSQL) have one primary and followers.
LayerJobProductsHow it survives a failure
DNS and CDNFind the site, serve copies near usersRoute 53, Cloudflare, Cloud CDNMany locations, health-checked records
Load balancerShare trafficHAProxy, Nginx, ALB, NLB, TraefikA pair with one address, or a managed service in several zones
ApplicationYour codeKubernetes pods, ECS tasksReplicas in several zones
CacheFast copies of dataRedis, MemcachedRedis: replica and promotion. Memcached: lose it and refill
DatabaseKeep the dataPostgreSQL, Aurora, CockroachDB, SpannerReplication and a new primary, or consensus

Four shelves of tools

  • Load balancers

    HAProxy (open source), Nginx (versatile), AWS ALB and NLB (managed), Traefik (made for containers).

  • Databases

    PostgreSQL with Patroni (self-hosted), Aurora (managed), CockroachDB (distributed), Cloud Spanner (99.999% across regions).

  • Cloud services

    Multi-AZ deployments (redundancy), global balancing (latency), managed databases (less work), auto scaling groups (elastic).

  • Orchestration

    Kubernetes (the standard), Docker Swarm (simple), ECS and EKS (on AWS), HashiCorp Nomad (lightweight).

Load balancers

Layer 4 or layer 7

Two ways to look at a request

Layer 4Layer 7
SeesIP address and portPath, headers, cookies
Can doForward connections very fastRoute by content, end TLS, cache, retry a request
Good forDatabases, games, anything not HTTPWeb and APIs
CostCannot choose by contentMore work per request

Four load balancers

ProductLayersStrong atMindBest for
HAProxy4 and 7Very fast, reliable, freeYou write the configuration and must pair it yourself (keepalived)Busy sites, TCP services
Nginx7, and 4 with the stream moduleWeb server, proxy and cache in one, large ecosystemFree version has passive checks only; active HTTP checks are in PlusWeb apps, API gateways
AWS ALB / NLB7 / 4Managed, scales and spans zonesTied to AWS, price per useAWS workloads
Traefik7 and 4Finds services in Kubernetes and Docker by itself, dashboardOwn concepts to learnContainers and microservices
Algorithms and health checks are covered in Achieving high availability and Load balancing. An NLB can end TLS too.

Databases

One primary, and copies that follow

Replication

The primary writes a log of changes and the replicas replay it. Replicas add read capacity, but their data may be a little old.

Four ways to run a relational database

ProductKindCopiesFailoverStrong atMind
PostgreSQL + PatroniSelf-managedAs many as the primary can feedAutomatic, leader lease in etcd, Consul or ZooKeeperFull control, open sourceYou run it, and etcd too
Amazon AuroraManagedUp to 15 readers, storage copied over 3 zonesTypically under 60 s, often under 30 s99.99% SLA for Multi-AZ, storage growsAWS only, price
CockroachDBDistributed SQL3 copies of each range by defaultBuilt in, by consensusEvery node takes reads and writes, multi-regionHigher write latency, needs several nodes
Cloud SpannerManaged, distributedSeveral zones or regionsBuilt in, by consensus99.999% multi-region, strong consistencyGoogle only, price, schema advice

PostgreSQL with Patroni

An app uses HAProxy, which sends connections to the current primary PostgreSQL machine. The primary replicates to a standby machine. Patroni on both machines keeps a leader lease in an etcd cluster of three machines.
Patroni on each machine asks etcd who holds the leader lease. If the primary stops renewing it, a standby takes the lease and is promoted, and HAProxy follows.

Synchronous or asynchronous replication

SynchronousAsynchronous
OrderWrite, wait for a replica, then commitWrite, commit, replicate afterwards
If the primary diesCommitted data is on a replicaThe last moments may be lost
PriceEvery write waits for the network; needs a reachable replicaFast writes
UseMoney, orders, between zonesRead replicas, between regions
What to lose and what to wait for is a choice of its own: Data integrity vs uptime.

Cache

Redis and Memcached

SetupSurvivesMind
Memcached, several nodesLoss of a node: those keys are read from the database againNo replication. Can the database take the extra reads?
Redis primary and replica + SentinelLoss of the primary: Sentinel promotes the replicaRun at least three Sentinels. Replication is asynchronous
Redis ClusterLoss of a master that has a replicaData is split. Acknowledged writes can be lost in a failover
Treat a cache as something that may be empty. If losing it would take the database down, it is not an optional layer. See Caching.

Cloud

Managed services in three clouds

JobAWSGoogle CloudAzure
Load balancingELB: ALB, NLBCloud Load BalancingAzure Load Balancer
Relational databaseRDS Multi-AZ, AuroraCloud SQL HAAzure SQL
Global databaseAurora Global, DynamoDB global tablesCloud SpannerCosmos DB
DNS and CDNRoute 53, CloudFrontCloud DNS, Cloud CDNTraffic Manager, Front Door
Object storageS3 (11 nines durability)Cloud StorageBlob Storage

What the contracts promise per month (checked November 2026)

ServiceAWSGoogle CloudAzure
Virtual machines, several zones99.99%99.99%99.99%
One virtual machine99.5%99.9%Depends on the disk
Load balancer99.99%, several zones99.99%99.99%, Standard
Managed databaseRDS Multi-AZ 99.95%, Aurora 99.99%Cloud SQL HA 99.95%, Enterprise Plus 99.99%Azure SQL 99.99%
Object storageS3 Standard 99.9%99.9% regional, 99.95% multi-regionBlob hot reads 99.9%
Global databaseDynamoDB global tables 99.999%Spanner multi-region 99.999%Cosmos DB multi-region 99.999%
Simplified. Each number needs a certain setup, so read the current SLA before you quote it. Azure's virtual machine, SQL and Blob figures and DynamoDB's were not re-read for this page.

Multi-AZ

Spread over three zones, each zone carries a third. Losing one means the other two carry half each, so keep every zone under about 53% of its capacity.

Kubernetes

Settings that keep pods available

FeatureWhat it doesExampleSaves you from
ReplicaSet (by a Deployment)Keeps the wanted number of podsreplicas: 3A crashed pod
PodDisruptionBudgetLimits voluntary evictionsminAvailable: 50% (2 of 3)A node upgrade that evicts too many. Not from crashes
Pod anti-affinitySpreads pods over nodestopologyKey: kubernetes.io/hostnameA lost node
Topology spreadSpreads pods evenly over zonesmaxSkew: 1, zone keyA lost zone
HorizontalPodAutoscalerChanges the number of pods by loadCPU target 70%Traffic growth, if it has minutes to react
Readiness probeTakes a pod out of trafficGET /readyRequests to a pod that is starting or busy
Liveness probeRestarts a containerGET /healthzA hung process

A rolling update of three pods

With 25% / 25% and 3 replicas, maxUnavailable rounds down to 0 and maxSurge rounds up to 1. So three ready pods stay, and a fourth starts before an old one stops.

How the percentages round

unavailable=⌊0.25×3⌋=0surge=⌈0.25×3⌉=1PDB=⌈0.5×3⌉=2\text{unavailable} = \lfloor 0.25 \times 3 \rfloor = 0 \qquad \text{surge} = \lceil 0.25 \times 3 \rceil = 1 \qquad \text{PDB} = \lceil 0.5 \times 3 \rceil = 2

Add it up

What can the whole stack promise?

A standard stack

0.9999LB×(1−0.013)app×0.9995DB=0.9994≈26 min a month0.9999_{\text{LB}} \times \left(1 - 0.01^3\right)_{\text{app}} \times 0.9995_{\text{DB}} = 0.9994 \approx 26\ \text{min a month}
Three app copies of 99% each are 99.9999% together, if independent. The database decides. With a 99.99% database it is 0.9998, about 8.7 minutes a month: still not four nines.

Choose by the target

Each step costs more than the one before. Stop at the first that meets the target.

Decide

Managed or self-hosted?

Managed fits when

  • The team is small
  • The default setup is enough
  • Failover at night must work without you
  • The bill is smaller than an engineer

Self-hosted fits when

  • You need a setting or extension they do not offer
  • The scale makes the bill larger than a team
  • Data must stay in your own building
  • You already run it well, with practice

Before you call it done

  1. 1

    Kill a pod, then a node

    Watch errors. The service should keep answering.

  2. 2

    Fail over the database

    Time it, and check that the application reconnects by itself.

  3. 3

    Empty the cache

    See if the database survives the extra reads.

  4. 4

    Cut a zone

    Is there room in the other two?

Summary

The whole topic in one minute.

Go layer by layer: DNS and CDN, load balancer, application, cache, database. Run stateless layers in several copies across zones. Give stateful layers replicas, a safe way to choose the primary, and a replication mode that fits what you may lose.

Managed services trade control and money for failover you do not have to build. Multiply the promises of the layers to see what the whole can offer, and remember that an SLA is a refund, not a guarantee.

  • Five layers: DNS and CDN, load balancer, application, cache, database.
  • Layer 4 forwards connections, layer 7 reads requests.
  • Patroni needs a consensus store; its leader lease is 30 seconds by default.
  • A PodDisruptionBudget covers voluntary disruptions only. Liveness must not check the database.
  • Multiply the layers. The weakest stateful one usually decides.

Sources